Inserts a block manager at the specified index

@param  BlockManagerInterface $element
@param  int                     $at
@return array
173589
public function insertAt(BlockManagerInterface $element, $at)
    {
        $elements = count($this->blockManagers);

        $leftPart = array_slice($this->blockManagers, 0 , $at);
        $rightPart = array_slice($this->blockManagers, $at , $elements);

        $this->blockManagers = array_merge($leftPart, array($element), $rightPart);

        return array(
            "left" => $leftPart,
            "right" => $rightPart,
        );
    }
547874
public function moveBlock($id, $parentId, $placeholder, $sort)
    {
        $block = $this->find($id);
        $version = $this->getNewVersion($block);
        $block = $this->find($id, $version);

        $parent = ($parentId) ? $this->find($parentId) : $block->getOwner();

        $block->setPosition($placeholder);
        $block->setRootVersion($version);

        $block->setParent($parent);
        $parent->addChild($block);

        $this->save($block);

        $siblings = $this->getSiblings($block, $version);

        if ($siblings) {
            $siblings = $this->sortBlocksByDirective($siblings, $sort);

            foreach ($siblings as $sibling) {
                $sibling->setRootVersion($version);
                $block->setSort($sibling->getSort());
                $this->save($sibling);
            }
        }
    }
758542
public function addElement(array $element)
    {
        if (array_key_exists('boxes', $element)) {
            if (array_key_exists($element['key'], $this->dashboard['boxes'])) {
                $this->dashboard['boxes'][$element['key']] = array_merge($this->dashboard['boxes'][$element['key']], $element['boxes']);
            } else {
                $this->dashboard['boxes'][$element['key']] = $element['boxes'];
            }
        }
        if (array_key_exists('cards', $element)) {
            if (array_key_exists($element['key'], $this->dashboard['cards'])) {
                $this->dashboard['cards'][$element['key']] = array_merge($this->dashboard['cards'][$element['key']], $element['cards']);
            } else {
                $this->dashboard['cards'][$element['key']] = $element['cards'];
            }
        }

        return $this;
    }
762609
public function remove_at( $index ) {
		$this->validate_index( $index );

		$elements = $this->elements;

		return $this->new_from_trusted(
			array_merge(
				array_slice( $elements, 0, $index ),
				array_slice( $elements, $index + 1, count( $elements ) )
			)
		);
	}
545923
public function set($index, $element)
    {
        if (null === $index) {
            $this->collections[] = $element;
        } else {
            $this->collections[$index] = $element;
        }

        return $this;
    }
1163242
public function insertElement(AbstractElement $element)
	{
		if (!($element instanceof $this->elementClassName)) {
			throw new \InvalidArgumentException("Indexed element must be instance of " . $this->elementClassName);
		}

		$id = $element->getId();

		if (isset($this->elements[$id])) {
			throw new DuplicateElementException("Element \"$id\" already indexed.");
		}

		$this->elements[$id] = $element;

		$indexedAttrs = array_intersect_key($element->getAttributes(), $this->index);
		foreach ($indexedAttrs as $key => $newValue) {
			$this->index[$key][$newValue][$id] = $element;
		}
	}
749150
public function add(ElementInterface $element)
    {
        $id = $element->id;

        if ($id === null) $id = $this->generateId();

        $this->checkId($id);

        $this->objects[$id] = $element;
    }
463858
public function put($element)
    {
        $nodeId   = count($this->_heap);
        $parentId = ($nodeId-1) >> 1;   // floor( ($nodeId-1)/2 )

        while ($nodeId != 0  &&  $this->_less($element, $this->_heap[$parentId])) {
            // Move parent node down
            $this->_heap[$nodeId] = $this->_heap[$parentId];

            // Move pointer to the next level of tree
            $nodeId   = $parentId;
            $parentId = ($nodeId-1) >> 1;   // floor( ($nodeId-1)/2 )
        }

        // Put new node into the tree
        $this->_heap[$nodeId] = $element;
    }
654449
public function removeBlock(Block $block)
	{
		if (! $this->equals($block->getPlaceHolder())
				|| ! $this->blocks->contains($block)) {
			throw new \InvalidArgumentException('Block does not belongs to this placeholder.');
		}

		$position = $block->getPosition();
	
		$this->blocks->removeElement($block);

		foreach ($this->blocks as $existingBlock) {
			if ($existingBlock->getPosition() > $position) {
				$existingBlock->setPosition($existingBlock->getPosition() - 1);
			}
		}
	}
199163
public function addElement($element, $name = null, $attrs = null) {
		switch (true) {
			case is_array($element):
				$newElement = new static($element);
				break;

			case $element instanceof self:
			case $element instanceof ListElement:
				$newElement = $element;
				break;

			default:
				$newElement = new ListElement($element, $attrs);
		}
		
		return parent::addElement($newElement, $name);
	}
92195
public function reorderBlocksAction()
	{
		$this->isPostRequest();
		$this->checkLock();

		$placeHolderName = $this->getRequestParameter('place_holder_id');

		$pageRequest = $this->createPageRequest();

		$placeHolder = $pageRequest->getPlaceHolderSet()
				->getFinalPlaceHolders()
				->offsetGet($placeHolderName);

		if ($placeHolder === null) {
			throw new \InvalidArgumentException(sprintf(
					'Placeholder [%s] not found in placeholders set.',
					$placeHolderName
			));
		}

		$blockSet = $pageRequest->getBlockSet()
				->getPlaceHolderBlockSet($placeHolder);

		$blockPositionMap = array_values($this->getRequestParameter('order', array()));

		if ($blockSet->count() !== count($blockPositionMap)) {
			// JS error or data spoofing
			throw new \UnexpectedValueException('Ordered elements and actual blocks count does not match.');
		}

		foreach ($blockPositionMap as $position => $id) {
			
			$block = $blockSet->findById($id);
			
			if ($block === null) {
				throw new \UnexpectedValueException(sprintf('Block [%s] not found.'));
			}

			$block->setPosition($position);
		}

		$this->getEntityManager()
				->flush();

		return new SupraJsonResponse();
	}
993334
protected function loadBlocks(array $blocks, ContainerBuilder $container)
    {
        foreach ($blocks as $blockName => $block) {
            $container
                ->register(
                    'elcodi.sitemap_element_provider.entity_' . $blockName,
                    'Elcodi\Component\Sitemap\Element\EntitySitemapElementProvider'
                )
                ->addArgument(new Reference($block['repository_service']))
                ->addArgument($block['method'])
                ->addArgument($block['arguments'])
                ->setPublic(false);

            $container
                ->register(
                    'elcodi.sitemap_element_generator.entity_' . $blockName,
                    'Elcodi\Component\Sitemap\Element\EntitySitemapElementGenerator'
                )
                ->addArgument(new Reference('elcodi.factory.sitemap_element'))
                ->addArgument(new Reference($block['transformer']))
                ->addArgument(new Reference('elcodi.sitemap_element_provider.entity_' . $blockName))
                ->addArgument($block['changeFrequency'])
                ->addArgument($block['priority'])
                ->setPublic(false);
        }

        return $this;
    }
80465
public function addBlock(Block $block)
	{
		if ($this->lock('block')) {
			$this->matchDiscriminator($block);
			if ($this->addUnique($this->blocks, $block)) {
				$block->setPlaceHolder($this);
			}
			$this->unlock('block');
		}
	}
874219
public function addElement($element){

        $elements = $this->formElements;
        $elements[] = $element;

        $this->formElements = $elements;

        return $this;
    }
1167310
private function internalCreateBlock(
        APIBlockCreateStruct $blockCreateStruct,
        PersistenceBlock $targetBlock,
        string $placeholder,
        ?int $position = null
    ): Block {
        $persistenceLayout = $this->layoutHandler->loadLayout($targetBlock->layoutId, Value::STATUS_DRAFT);

        $createdBlock = $this->transaction(
            function () use ($blockCreateStruct, $persistenceLayout, $targetBlock, $placeholder, $position): PersistenceBlock {
                $blockDefinition = $blockCreateStruct->getDefinition();

                $createdBlock = $this->blockHandler->createBlock(
                    BlockCreateStruct::fromArray(
                        [
                            'status' => $targetBlock->status,
                            'position' => $position,
                            'definitionIdentifier' => $blockDefinition->getIdentifier(),
                            'viewType' => $blockCreateStruct->viewType,
                            'itemViewType' => $blockCreateStruct->itemViewType,
                            'name' => $blockCreateStruct->name,
                            'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                            'isTranslatable' => $blockCreateStruct->isTranslatable,
                            'parameters' => iterator_to_array(
                                $this->parameterMapper->serializeValues(
                                    $blockDefinition,
                                    $blockCreateStruct->getParameterValues()
                                )
                            ),
                            'config' => iterator_to_array(
                                $this->configMapper->serializeValues(
                                    $blockCreateStruct->getConfigStructs(),
                                    $blockDefinition->getConfigDefinitions()
                                )
                            ),
                        ]
                    ),
                    $persistenceLayout,
                    $targetBlock,
                    $placeholder
                );

                $collectionCreateStructs = $blockCreateStruct->getCollectionCreateStructs();
                if (count($collectionCreateStructs) > 0) {
                    foreach ($collectionCreateStructs as $identifier => $collectionCreateStruct) {
                        $createdCollection = $this->collectionHandler->createCollection(
                            CollectionCreateStruct::fromArray(
                                [
                                    'status' => Value::STATUS_DRAFT,
                                    'offset' => $collectionCreateStruct->offset,
                                    'limit' => $collectionCreateStruct->limit,
                                    'alwaysAvailable' => $blockCreateStruct->alwaysAvailable,
                                    'isTranslatable' => $blockCreateStruct->isTranslatable,
                                    'mainLocale' => $persistenceLayout->mainLocale,
                                ]
                            )
                        );

                        if ($collectionCreateStruct->queryCreateStruct instanceof APIQueryCreateStruct) {
                            $queryType = $collectionCreateStruct->queryCreateStruct->getQueryType();
                            $this->collectionHandler->createQuery(
                                $createdCollection,
                                QueryCreateStruct::fromArray(
                                    [
                                        'type' => $queryType->getType(),
                                        'parameters' => iterator_to_array(
                                            $this->parameterMapper->serializeValues(
                                                $queryType,
                                                $collectionCreateStruct->queryCreateStruct->getParameterValues()
                                            )
                                        ),
                                    ]
                                )
                            );
                        }

                        if ($blockCreateStruct->isTranslatable) {
                            foreach ($persistenceLayout->availableLocales as $locale) {
                                if ($locale !== $persistenceLayout->mainLocale) {
                                    $createdCollection = $this->collectionHandler->createCollectionTranslation(
                                        $createdCollection,
                                        $locale,
                                        $createdCollection->mainLocale
                                    );
                                }
                            }
                        }

                        $this->blockHandler->createCollectionReference(
                            $createdBlock,
                            $createdCollection,
                            (string) $identifier
                        );
                    }
                }

                return $createdBlock;
            }
        );

        return $this->mapper->mapBlock($createdBlock);
    }
344299
public function addElement($element, $name = null, $attrsTerm = null, $attrsDesc = null) {
		if ($element instanceof DescListElement) {
			return parent::addElement($element, $name);
		}
		
		if (! is_array($element)) {
			throw new Exception('Element must be an array or the "ListElement" instance');
		}
		
		if (! isset($element[0], $element[1])) {
			throw new Exception('Element definition array must contain "0" and "1" offsets');
		}
		
		$newElement = new DescListElement($element[0], $element[1], $attrsTerm, $attrsDesc);
		
		return parent::addElement($newElement, $name);
	}
1351267
public function addElement($element, $title = null, $name = null, $attrs = null) {
		if (! $element instanceof Element &&
			! $element instanceof Divider) {
			
			if ($element === self::DIVIDER) {
				$element = new Divider(null, $attrs);
			} else {
				if ($title === null) {
					$title = $element;
				}
				
				$element = new Element($element, $title, $attrs);
			}
		}
		
		if ($name === null && $title !== null) {
			$name = $title;
		}
		
		return parent::addElement($element, $name);
	}