Validates item creation parameters from the request.

@param \Netgen\BlockManager\API\Values\Block\Block $block
@param string $collectionIdentifier
@param mixed $items
540749
private function validateAddItems(Block $block, string $collectionIdentifier, $items): void
    {
        $this->validate(
            $items,
            [
                new Constraints\Type(['type' => 'array']),
                new Constraints\NotBlank(),
                new Constraints\All(
                    [
                        'constraints' => new Constraints\Collection(
                            [
                                'fields' => [
                                    'value' => [
                                        new Constraints\NotNull(),
                                        new Constraints\Type(['type' => 'scalar']),
                                    ],
                                    'value_type' => [
                                        new Constraints\NotBlank(),
                                        new Constraints\Type(['type' => 'string']),
                                    ],
                                    'position' => new Constraints\Optional(
                                        [
                                            new Constraints\NotNull(),
                                            new Constraints\Type(['type' => 'int']),
                                        ]
                                    ),
                                ],
                            ]
                        ),
                    ]
                ),
            ],
            'items'
        );

        $blockDefinition = $block->getDefinition();
        if (!$blockDefinition->hasCollection($collectionIdentifier)) {
            return;
        }

        $collectionConfig = $blockDefinition->getCollection($collectionIdentifier);

        foreach ($items as $item) {
            if (!$collectionConfig->isValidItemType($item['value_type'])) {
                throw ValidationException::validationFailed(
                    'value_type',
                    sprintf(
                        'Value type "%s" is not allowed in selected block.',
                        $item['value_type']
                    )
                );
            }
        }
    }
574582
public function editCollectionItem($collection_id, $collection_item_id = null)
    {
        $this->setCollectionCollection($collection_id);
        $this->setCollectionCollectionItem($collection_item_id);
        $this->setTitleEditCollectionItem();
        $this->setBreadcrumbEditCollectionItem();

        $this->setData('collection', $this->data_collection);
        $this->setData('collection_item', $this->data_collection_item);
        $this->setData('handler', $this->getHandlerCollectionItem());
        $this->setData('weight', $this->collection_item->getNextWeight($collection_id));

        $this->submitEditCollectionItem();

        $this->setJsEditCollectionItem();
        $this->outputEditCollectionItem();
    }
676171
private function validateBlockTypes(array $blockTypes, array $blockDefinitions): void
    {
        foreach ($blockTypes as $identifier => $blockType) {
            if (!isset($blockDefinitions[$blockType['definition_identifier']])) {
                throw new RuntimeException(
                    sprintf(
                        'Block definition "%s" used in "%s" block type does not exist.',
                        $blockType['definition_identifier'],
                        $identifier
                    )
                );
            }
        }
    }
720887
protected function compileNestedBlock(Block $block, $selectors)
    {
        $this->pushEnv($block);

        $this->scope = $this->makeOutputBlock($block->type, $selectors);
        $this->scope->parent->children[] = $this->scope;

        $this->compileChildrenNoReturn($block->children, $this->scope);

        $this->scope = $this->scope->parent;

        $this->popEnv();
    }
1330855
public function getValidBlockItems(Block $block)
    {
        $dbHandler = $this->getConnection();
        $q = $dbHandler->createSelectQuery();
        $q
            ->select('object_id, ezm_pool.node_id, ezm_pool.priority, ts_publication, ts_visible, rotation_until, moved_to')
            ->from($dbHandler->quoteTable('ezm_pool'))
            ->innerJoin(
                $dbHandler->quoteTable('ezcontentobject_tree'),
                $q->expr->eq('ezcontentobject_tree.node_id', 'ezm_pool.node_id')
            )
            ->where(
                $q->expr->eq('block_id', $q->bindValue($block->id)),
                $q->expr->gt('ts_visible', $q->bindValue(0, null, PDO::PARAM_INT)),
                $q->expr->eq('ts_hidden', $q->bindValue(0, null, PDO::PARAM_INT))
            )
            ->orderBy('priority', SelectQuery::DESC);

        $stmt = $q->prepare();
        $stmt->execute();
        $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
        $items = array();
        foreach ($rows as $row) {
            $items[] = $this->buildBlockItem(
                $row + array(
                    'block_id' => $block->id,
                    'ts_hidden' => 0,
                )
            );
        }

        return $items;
    }
1197453
public function createCursorForCollection(RepositoryCollection $collection)
    {
        $ids = array_keys($this->cachedObjectData);

        return new UniqueIdentifierListCursor(array_values($ids), $this->modelClassName);
    }
1220417
private function validateLayoutTypes(array $layoutTypes, array $blockDefinitions): void
    {
        foreach ($layoutTypes as $layoutType => $layoutTypeConfig) {
            foreach ($layoutTypeConfig['zones'] as $zoneConfig) {
                foreach ($zoneConfig['allowed_block_definitions'] as $blockDefinition) {
                    if (!isset($blockDefinitions[$blockDefinition])) {
                        throw new RuntimeException(
                            sprintf(
                                'Block definition "%s" used in "%s" layout type does not exist.',
                                $blockDefinition,
                                $layoutType
                            )
                        );
                    }
                }
            }
        }
    }
814956
protected function _setBlock($block)
    {
        if ($block !== null && !($block instanceof BlockInterface)) {
            throw $this->_createInvalidArgumentException(
                $this->__('Invalid block'),
                null,
                null,
                $block
            );
        }

        $this->block = $block;
    }
1334673
public function getUserBlockList($userIdentifier, $accessToken, $limit = 25, $offset = 0)
    {
        if ($this->apiVersionIsGreaterThanV3() && !is_numeric($userIdentifier)) {
            throw new InvalidIdentifierException('user');
        }

        if (!$this->isValidLimit($limit)) {
            throw new InvalidLimitException();
        }

        if (!$this->isValidOffset($offset)) {
            throw new InvalidOffsetException();
        }

        $params = [
            'limit' => intval($limit),
            'offset' => intval($offset),
        ];

        return $this->get(sprintf('users/%s/blocks', $userIdentifier), $params, $accessToken);
    }
1030223
public function generateItems(ItemInterface $templateItem, array $collections)
    {
        $result = [];
        $taxonomyCollection = [];
        $termCollection = [];
        $templateAttributes = $templateItem->getAttributes();
        $options = $this->buildAttributesResolver($templateItem);
        $taxonomyAttribute = $options['taxonomy_attribute'];
        $permalink = $options['permalink'];

        $templateAttributes['permalink'] = $options['pagination_permalink'];
        $templatePath = dirname($templateItem->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE));

        $items = (new ArrayWrapper($collections))->flatten();

        foreach ($items as $item) {
            $attributes = $item->getAttributes();

            if (isset($attributes[$taxonomyAttribute]) === false) {
                continue;
            }

            $terms = (array) $attributes[$taxonomyAttribute];

            foreach ($terms as $term) {
                if (empty(trim($term)) === true) {
                    continue;
                }

                $term = $this->normalizeTerm($term);
                $slugedTerm = (new StringWrapper($term))->slug();

                if (isset($taxonomyCollection[$slugedTerm]) === false) {
                    $taxonomyCollection[$slugedTerm] = [];
                }

                if (isset($termCollection[$slugedTerm]) === false) {
                    $termCollection[$slugedTerm] = [];
                }

                if (in_array($item, $taxonomyCollection[$slugedTerm]) === false) {
                    $taxonomyCollection[$slugedTerm][] = $item;
                }

                if (in_array($term, $termCollection[$slugedTerm]) === false) {
                    $termCollection[$slugedTerm][] = $term;
                }
            }
        }

        ksort($taxonomyCollection);

        foreach ($taxonomyCollection as $slugedTerm => $items) {
            $templateAttributes['provider'] = 'site.'.$slugedTerm;
            $templateAttributes['term'] = $termCollection[$slugedTerm][0];
            $templateItem->setAttributes($templateAttributes);
            $slugedTermPath = $this->getTermRelativePath($templatePath, $permalink, $slugedTerm);
            $templateItem->setPath($slugedTermPath, ItemInterface::SNAPSHOT_PATH_RELATIVE);

            $paginationGenerator = new PaginationGenerator();
            $itemsGenerated = $paginationGenerator->generateItems($templateItem, [$slugedTerm => $items]);

            $this->setTermsPermalink($items, $taxonomyAttribute, $termCollection[$slugedTerm], $slugedTermPath);

            $result = array_merge($result, $itemsGenerated);
        }

        return $result;
    }
7399
public function renderCollectionPager(Pagerfanta $pagerfanta, Block $block, string $collectionIdentifier, array $options = []): string
    {
        $options['block'] = $block;
        $options['collection_identifier'] = $collectionIdentifier;

        return $this->pagerfantaView->render($pagerfanta, $this->routeGenerator, $options);
    }
381140
private function verifyItemExistenceInSubItemList(string $itemName, string $itemType, string $containerName, bool $itemShouldExist): void
    {
        $isItemInTable = PageObjectFactory::createPage($this->utilityContext, ContentItemPage::PAGE_NAME, $containerName)
            ->subItemList->table->isElementInTable($itemName, $itemType);

        $itemShouldExistString = $itemShouldExist ? '' : 'n\'t';

        if ($isItemInTable !== $itemShouldExist) {
            Assert::fail(sprintf('%s "%s" should%s be on %s Sub-items list', $itemType, $itemName, $itemShouldExistString, $containerName));
        }
    }
457854
protected function verifyContainsEntitiesOnly(Collection $collection) {
			$check = $collection->forAll(function($key, $element) {
				return $element instanceof EntityInterface;
			});

			if (!$check)
				throw new \InvalidArgumentException('Items in the collection must all implement ' .
					EntityInterface::class);
		}
1026135
public function createCollectionReference(CollectionReference $collectionReference): void
    {
        $query = $this->connection->createQueryBuilder();

        $query->insert('ngbm_block_collection')
            ->values(
                [
                    'block_id' => ':block_id',
                    'block_status' => ':block_status',
                    'collection_id' => ':collection_id',
                    'collection_status' => ':collection_status',
                    'identifier' => ':identifier',
                ]
            )
            ->setParameter('block_id', $collectionReference->blockId, Type::INTEGER)
            ->setParameter('block_status', $collectionReference->blockStatus, Type::INTEGER)
            ->setParameter('collection_id', $collectionReference->collectionId, Type::INTEGER)
            ->setParameter('collection_status', $collectionReference->collectionStatus, Type::INTEGER)
            ->setParameter('identifier', $collectionReference->identifier, Type::STRING);

        $query->execute();
    }
1115327
public function addBlock(JMSAbstractBlock $item)
    {
        if (!empty($this->allowedBlocks) && !in_array($item->getBlockName(), $this->allowedBlocks)) {
            throw new BadBlockTypeForAddToCollection('Block class '.$item->getBlockName().' not allowed to add this collection');
        }

        $this->offsetSet(null, $item);

        return $this;
    }
791839
private function verifyElementsType(array $elements): void
    {
        $allowedType = $this->getAllowedType();
        if ($allowedType !== DTO::class
            && (!\class_exists($allowedType) || !\in_array(DTO::class, \class_implements($allowedType), true))
        ) {
            throw new InvalidCollectionTypeException(\sprintf(
                'Allowed class type for %s should be a %s, %s given',
                static::class,
                DTO::class,
                $allowedType
            ));
        }

        foreach ($elements as $element) {
            if (!\is_object($element) || !\is_a($element, $allowedType)) {
                throw new InvalidParameterException(\sprintf(
                    'All elements of %s should be instances of %s, %s given',
                    static::class,
                    $allowedType,
                    \is_object($element) ? \get_class($element) : \gettype($element)
                ));
            }
        }
    }
1050947
protected function blockSelectors(OutputBlock $block)
    {
        $inner = $this->indentStr();

        $this->write($inner
            . implode($this->tagSeparator, $block->selectors)
            . $this->open . $this->break);
    }