public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
    {
        $validationErrors = array();

        if ($this->isEmptyValue($fieldValue)) {
            return $validationErrors;
        }

        $fieldSettings = $fieldDefinition->getFieldSettings();

        if ((!isset($fieldSettings['isMultiple']) || $fieldSettings['isMultiple'] === false)
            && count($fieldValue->selection) > 1) {
            $validationErrors[] = new ValidationError(
                'Field definition does not allow multiple options to be selected.',
                null,
                array(),
                'selection'
            );
        }

        foreach ($fieldValue->selection as $optionIndex) {
            if (!isset($fieldSettings['options'][$optionIndex]) && empty($fieldSettings['multilingualOptions'])) {
                $validationErrors[] = new ValidationError(
                    'Option with index %index% does not exist in the field definition.',
                    null,
                    array(
                        '%index%' => $optionIndex,
                    ),
                    'selection'
                );
            }
        }

        //@todo: find a way to include selection language
        if (isset($fieldSettings['multilingualOptions'])) {
            $possibleOptionIndexesByLanguage = array_map(function ($languageOptionIndexes) {
                return array_keys($languageOptionIndexes);
            }, $fieldSettings['multilingualOptions']);

            $possibleOptionIndexes = call_user_func_array('array_merge', $possibleOptionIndexesByLanguage);

            foreach ($fieldValue->selection as $optionIndex) {
                if (!in_array($optionIndex, $possibleOptionIndexes)) {
                    $validationErrors[] = new ValidationError(
                        'Option with index %index% does not exist in the field definition.',
                        null,
                        array(
                            '%index%' => $optionIndex,
                        ),
                        'selection'
                    );
                }
            }
        }

        return $validationErrors;
    }
public function validate(FieldDefinition $fieldDefinition, SPIValue $fieldValue)
    {
        $validationErrors = array();

        if ($this->isEmptyValue($fieldValue)) {
            return $validationErrors;
        }

        $fieldSettings = $fieldDefinition->getFieldSettings();

        if ((!isset($fieldSettings['isMultiple']) || $fieldSettings['isMultiple'] === false)
            && count($fieldValue->selection) > 1) {
            $validationErrors[] = new ValidationError(
                'Field definition does not allow multiple options to be selected.',
                null,
                array(),
                'selection'
            );
        }

        foreach ($fieldValue->selection as $optionIndex) {
            if (!isset($fieldSettings['options'][$optionIndex]) && empty($fieldSettings['multilingualOptions'])) {
                $validationErrors[] = new ValidationError(
                    'Option with index %index% does not exist in the field definition.',
                    null,
                    array(
                        '%index%' => $optionIndex,
                    ),
                    'selection'
                );
            }
        }

        //@todo: find a way to include selection language
        if (isset($fieldSettings['multilingualOptions'])) {
            $possibleOptionIndexesByLanguage = array_map(function ($languageOptionIndexes) {
                return array_keys($languageOptionIndexes);
            }, $fieldSettings['multilingualOptions']);

            $possibleOptionIndexes = call_user_func_array('array_merge', $possibleOptionIndexesByLanguage);

            foreach ($fieldValue->selection as $optionIndex) {
                if (!in_array($optionIndex, $possibleOptionIndexes)) {
                    $validationErrors[] = new ValidationError(
                        'Option with index %index% does not exist in the field definition.',
                        null,
                        array(
                            '%index%' => $optionIndex,
                        ),
                        'selection'
                    );
                }
            }
        }

        return $validationErrors;
    }
public function validate ( FieldDefinition $ fieldDefinition , SPIValue $ fieldValue ) { $ validationErrors = array ( ) ; if ( $ this -> isEmptyValue ( $ fieldValue ) ) { return $ validationErrors ; } $ fieldSettings = $ fieldDefinition -> getFieldSettings ( ) ; if ( ( ! isset ( $ fieldSettings [ 'isMultiple' ] ) || $ fieldSettings [ 'isMultiple' ] === false ) && count ( $ fieldValue -> selection ) > 1 ) { $ validationErrors [ ] = new ValidationError ( 'Field definition does not allow multiple options to be selected.' , null , array ( ) , 'selection' ) ; } foreach ( $ fieldValue -> selection as $ optionIndex ) { if ( ! isset ( $ fieldSettings [ 'options' ] [ $ optionIndex ] ) && empty ( $ fieldSettings [ 'multilingualOptions' ] ) ) { $ validationErrors [ ] = new ValidationError ( 'Option with index %index% does not exist in the field definition.' , null , array ( '%index%' => $ optionIndex , ) , 'selection' ) ; } } //@todo: find a way to include selection language if ( isset ( $ fieldSettings [ 'multilingualOptions' ] ) ) { $ possibleOptionIndexesByLanguage = array_map ( function ( $ languageOptionIndexes ) { return array_keys ( $ languageOptionIndexes ) ; } , $ fieldSettings [ 'multilingualOptions' ] ) ; $ possibleOptionIndexes = call_user_func_array ( 'array_merge' , $ possibleOptionIndexesByLanguage ) ; foreach ( $ fieldValue -> selection as $ optionIndex ) { if ( ! in_array ( $ optionIndex , $ possibleOptionIndexes ) ) { $ validationErrors [ ] = new ValidationError ( 'Option with index %index% does not exist in the field definition.' , null , array ( '%index%' => $ optionIndex , ) , 'selection' ) ; } } } return $ validationErrors ; }
Validates field value against 'isMultiple' and 'options' settings.

Does not use validators.

@throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException

@param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition The field definition of the field
@param \eZ\Publish\Core\FieldType\Selection\Value $fieldValue The field value for which an action is performed

@return \eZ\Publish\SPI\FieldType\ValidationError[]
Validates field value against isMultiple and options settings .