eZ\Publish\Core\REST\Common\Input\FieldTypeParser::parseValidatorConfiguration PHP Method

parseValidatorConfiguration() public method

Parses the given $configurationHash using the FieldType identified by $fieldTypeIdentifier.
public parseValidatorConfiguration ( string $fieldTypeIdentifier, mixed $configurationHash ) : mixed
$fieldTypeIdentifier string
$configurationHash mixed
return mixed
    public function parseValidatorConfiguration($fieldTypeIdentifier, $configurationHash)
    {
        if ($this->fieldTypeProcessorRegistry->hasProcessor($fieldTypeIdentifier)) {
            $fieldTypeProcessor = $this->fieldTypeProcessorRegistry->getProcessor($fieldTypeIdentifier);
            $configurationHash = $fieldTypeProcessor->preProcessValidatorConfigurationHash($configurationHash);
        }
        $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier);
        return $fieldType->validatorConfigurationFromHash($configurationHash);
    }

Usage Example

 /**
  * Parse input structure
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     $fieldDefinitionUpdate = $this->contentTypeService->newFieldDefinitionUpdateStruct();
     if (array_key_exists('identifier', $data)) {
         $fieldDefinitionUpdate->identifier = $data['identifier'];
     }
     // @todo XSD says that descriptions is mandatory, but field definition can be updated without it
     if (array_key_exists('names', $data)) {
         if (!is_array($data['names']) || !array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
             throw new Exceptions\Parser("Invalid 'names' element for FieldDefinitionUpdate.");
         }
         $fieldDefinitionUpdate->names = $this->parserTools->parseTranslatableList($data['names']);
     }
     // @todo XSD says that descriptions is mandatory, but field definition can be updated without it
     if (array_key_exists('descriptions', $data)) {
         if (!is_array($data['descriptions']) || !array_key_exists('value', $data['descriptions']) || !is_array($data['descriptions']['value'])) {
             throw new Exceptions\Parser("Invalid 'descriptions' element for FieldDefinitionUpdate.");
         }
         $fieldDefinitionUpdate->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
     }
     // @todo XSD says that fieldGroup is mandatory, but field definition can be updated without it
     if (array_key_exists('fieldGroup', $data)) {
         $fieldDefinitionUpdate->fieldGroup = $data['fieldGroup'];
     }
     // @todo XSD says that position is mandatory, but field definition can be updated without it
     if (array_key_exists('position', $data)) {
         $fieldDefinitionUpdate->position = (int) $data['position'];
     }
     // @todo XSD says that isTranslatable is mandatory, but field definition can be updated without it
     if (array_key_exists('isTranslatable', $data)) {
         $fieldDefinitionUpdate->isTranslatable = $this->parserTools->parseBooleanValue($data['isTranslatable']);
     }
     // @todo XSD says that isRequired is mandatory, but field definition can be updated without it
     if (array_key_exists('isRequired', $data)) {
         $fieldDefinitionUpdate->isRequired = $this->parserTools->parseBooleanValue($data['isRequired']);
     }
     // @todo XSD says that isInfoCollector is mandatory, but field definition can be updated without it
     if (array_key_exists('isInfoCollector', $data)) {
         $fieldDefinitionUpdate->isInfoCollector = $this->parserTools->parseBooleanValue($data['isInfoCollector']);
     }
     // @todo XSD says that isSearchable is mandatory, but field definition can be updated without it
     if (array_key_exists('isSearchable', $data)) {
         $fieldDefinitionUpdate->isSearchable = $this->parserTools->parseBooleanValue($data['isSearchable']);
     }
     $fieldDefinition = $this->getFieldDefinition($data);
     // @todo XSD says that defaultValue is mandatory, but content type can be created without it
     if (array_key_exists('defaultValue', $data)) {
         $fieldDefinitionUpdate->defaultValue = $this->fieldTypeParser->parseValue($fieldDefinition->fieldTypeIdentifier, $data['defaultValue']);
     }
     if (array_key_exists('validatorConfiguration', $data)) {
         $fieldDefinitionUpdate->validatorConfiguration = $this->fieldTypeParser->parseValidatorConfiguration($fieldDefinition->fieldTypeIdentifier, $data['validatorConfiguration']);
     }
     if (array_key_exists('fieldSettings', $data)) {
         $fieldDefinitionUpdate->fieldSettings = $this->fieldTypeParser->parseFieldSettings($fieldDefinition->fieldTypeIdentifier, $data['fieldSettings']);
     }
     return $fieldDefinitionUpdate;
 }
All Usage Examples Of eZ\Publish\Core\REST\Common\Input\FieldTypeParser::parseValidatorConfiguration