bundles/BlockManagerBundle/Controller/API/V1/BlockCollection/ChangeCollectionType.php
private function validateChangeCollectionType(Block $block, string $collectionIdentifier, int $newType, string $queryType): void
    {
        $this->validate(
            $newType,
            [
                new Constraints\NotBlank(),
                new Constraints\Choice(
                    [
                        'choices' => [
                            Collection::TYPE_MANUAL,
                            Collection::TYPE_DYNAMIC,
                        ],
                        'strict' => true,
                    ]
                ),
            ],
            'new_type'
        );

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

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

        if ($newType === Collection::TYPE_DYNAMIC) {
            if (!$collectionConfig->isValidQueryType($queryType)) {
                throw ValidationException::validationFailed(
                    'new_type',
                    sprintf(
                        'Query type "%s" is not allowed in selected block.',
                        $queryType
                    )
                );
            }
        } elseif ($newType === Collection::TYPE_MANUAL) {
            if ($collectionConfig->getValidItemTypes() === []) {
                throw ValidationException::validationFailed(
                    'new_type',
                    'Selected block does not allow manual collections.'
                );
            }
        }
    }
private function validateChangeCollectionType(Block $block, string $collectionIdentifier, int $newType, string $queryType): void
    {
        $this->validate(
            $newType,
            [
                new Constraints\NotBlank(),
                new Constraints\Choice(
                    [
                        'choices' => [
                            Collection::TYPE_MANUAL,
                            Collection::TYPE_DYNAMIC,
                        ],
                        'strict' => true,
                    ]
                ),
            ],
            'new_type'
        );

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

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

        if ($newType === Collection::TYPE_DYNAMIC) {
            if (!$collectionConfig->isValidQueryType($queryType)) {
                throw ValidationException::validationFailed(
                    'new_type',
                    sprintf(
                        'Query type "%s" is not allowed in selected block.',
                        $queryType
                    )
                );
            }
        } elseif ($newType === Collection::TYPE_MANUAL) {
            if ($collectionConfig->getValidItemTypes() === []) {
                throw ValidationException::validationFailed(
                    'new_type',
                    'Selected block does not allow manual collections.'
                );
            }
        }
    }
private function validateChangeCollectionType ( Block $ block , string $ collectionIdentifier , int $ newType , string $ queryType ) : void { $ this -> validate ( $ newType , [ new Constraints \ NotBlank ( ) , new Constraints \ Choice ( [ 'choices' => [ Collection :: TYPE_MANUAL , Collection :: TYPE_DYNAMIC , ] , 'strict' => true , ] ) , ] , 'new_type' ) ; $ blockDefinition = $ block -> getDefinition ( ) ; if ( ! $ blockDefinition -> hasCollection ( $ collectionIdentifier ) ) { return ; } $ collectionConfig = $ blockDefinition -> getCollection ( $ collectionIdentifier ) ; if ( $ newType === Collection :: TYPE_DYNAMIC ) { if ( ! $ collectionConfig -> isValidQueryType ( $ queryType ) ) { throw ValidationException :: validationFailed ( 'new_type' , sprintf ( 'Query type "%s" is not allowed in selected block.' , $ queryType ) ) ; } } elseif ( $ newType === Collection :: TYPE_MANUAL ) { if ( $ collectionConfig -> getValidItemTypes ( ) === [ ] ) { throw ValidationException :: validationFailed ( 'new_type' , 'Selected block does not allow manual collections.' ) ; } } }
Validates block creation parameters from the request.

@throws \Netgen\BlockManager\Exception\Validation\ValidationException If validation failed
Validates block creation parameters from the request .