parseValue() public method

Parses the given $value using the FieldType identified by $fieldTypeIdentifier.
public parseValue ( mixed $fieldTypeIdentifier, mixed $value ) : mixed
$fieldTypeIdentifier mixed
$value mixed
return mixed
Example #1
1
 /**
  * Parse input structure.
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     $contentType = null;
     if (array_key_exists('ContentType', $data) && is_array($data['ContentType'])) {
         if (!array_key_exists('_href', $data['ContentType'])) {
             throw new Exceptions\Parser("Missing '_href' attribute for ContentType element in UserCreate.");
         }
         $contentType = $this->contentTypeService->loadContentType($this->requestParser->parseHref($data['ContentType']['_href'], 'contentTypeId'));
     }
     if (!array_key_exists('mainLanguageCode', $data)) {
         throw new Exceptions\Parser("Missing 'mainLanguageCode' element for UserCreate.");
     }
     if (!array_key_exists('login', $data)) {
         throw new Exceptions\Parser("Missing 'login' element for UserCreate.");
     }
     if (!array_key_exists('email', $data)) {
         throw new Exceptions\Parser("Missing 'email' element for UserCreate.");
     }
     if (!array_key_exists('password', $data)) {
         throw new Exceptions\Parser("Missing 'password' element for UserCreate.");
     }
     $userCreateStruct = $this->userService->newUserCreateStruct($data['login'], $data['email'], $data['password'], $data['mainLanguageCode'], $contentType);
     if (array_key_exists('Section', $data) && is_array($data['Section'])) {
         if (!array_key_exists('_href', $data['Section'])) {
             throw new Exceptions\Parser("Missing '_href' attribute for Section element in UserCreate.");
         }
         $userCreateStruct->sectionId = $this->requestParser->parseHref($data['Section']['_href'], 'sectionId');
     }
     if (array_key_exists('remoteId', $data)) {
         $userCreateStruct->remoteId = $data['remoteId'];
     }
     if (array_key_exists('enabled', $data)) {
         $userCreateStruct->enabled = $this->parserTools->parseBooleanValue($data['enabled']);
     }
     if (!array_key_exists('fields', $data) || !is_array($data['fields']) || !is_array($data['fields']['field'])) {
         throw new Exceptions\Parser("Missing or invalid 'fields' element for UserCreate.");
     }
     foreach ($data['fields']['field'] as $fieldData) {
         if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
             throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for UserCreate.");
         }
         $fieldDefinition = $userCreateStruct->contentType->getFieldDefinition($fieldData['fieldDefinitionIdentifier']);
         if (!$fieldDefinition) {
             throw new Exceptions\Parser("'{$fieldData['fieldDefinitionIdentifier']}' is invalid field definition identifier for '{$userCreateStruct->contentType->identifier}' content type in UserCreate.");
         }
         if (!array_key_exists('fieldValue', $fieldData)) {
             throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in UserCreate.");
         }
         $fieldValue = $this->fieldTypeParser->parseValue($fieldDefinition->fieldTypeIdentifier, $fieldData['fieldValue']);
         $languageCode = null;
         if (array_key_exists('languageCode', $fieldData)) {
             $languageCode = $fieldData['languageCode'];
         }
         $userCreateStruct->setField($fieldData['fieldDefinitionIdentifier'], $fieldValue, $languageCode);
     }
     return $userCreateStruct;
 }
 /**
  * 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;
 }
 /**
  * Parse input structure.
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @todo Error handling
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     return new Values\ContentType\FieldDefinition(array('id' => $data['_href'], 'identifier' => $data['identifier'], 'fieldTypeIdentifier' => $data['fieldType'], 'fieldGroup' => $data['fieldGroup'], 'position' => (int) $data['position'], 'isTranslatable' => $this->parserTools->parseBooleanValue($data['isTranslatable']), 'isRequired' => $this->parserTools->parseBooleanValue($data['isRequired']), 'isInfoCollector' => $this->parserTools->parseBooleanValue($data['isInfoCollector']), 'isSearchable' => $this->parserTools->parseBooleanValue($data['isSearchable']), 'names' => isset($data['names']) ? $this->parserTools->parseTranslatableList($data['names']) : null, 'descriptions' => isset($data['descriptions']) ? $this->parserTools->parseTranslatableList($data['descriptions']) : null, 'defaultValue' => $this->fieldTypeParser->parseValue($data['fieldType'], $data['defaultValue']), 'fieldSettings' => $this->fieldTypeParser->parseFieldSettings($data['fieldType'], $data['fieldSettings']), 'validators' => $this->fieldTypeParser->parseValidatorConfiguration($data['fieldType'], $data['validatorConfiguration'])));
 }
 /**
  * Parse input structure
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\Core\REST\Server\Values\RestContentCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     if (!array_key_exists('LocationCreate', $data) || !is_array($data['LocationCreate'])) {
         throw new Exceptions\Parser("Missing or invalid 'LocationCreate' element for ContentCreate.");
     }
     $locationCreateStruct = $this->locationCreateParser->parse($data['LocationCreate'], $parsingDispatcher);
     if (!array_key_exists('ContentType', $data) || !is_array($data['ContentType'])) {
         throw new Exceptions\Parser("Missing or invalid 'ContentType' element for ContentCreate.");
     }
     if (!array_key_exists('_href', $data['ContentType'])) {
         throw new Exceptions\Parser("Missing '_href' attribute for ContentType element in ContentCreate.");
     }
     if (!array_key_exists('mainLanguageCode', $data)) {
         throw new Exceptions\Parser("Missing 'mainLanguageCode' element for ContentCreate.");
     }
     $contentType = $this->contentTypeService->loadContentType($this->requestParser->parseHref($data['ContentType']['_href'], 'contentTypeId'));
     $contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, $data['mainLanguageCode']);
     if (array_key_exists('Section', $data) && is_array($data['Section'])) {
         if (!array_key_exists('_href', $data['Section'])) {
             throw new Exceptions\Parser("Missing '_href' attribute for Section element in ContentCreate.");
         }
         $contentCreateStruct->sectionId = $this->requestParser->parseHref($data['Section']['_href'], 'sectionId');
     }
     if (array_key_exists('alwaysAvailable', $data)) {
         $contentCreateStruct->alwaysAvailable = $this->parserTools->parseBooleanValue($data['alwaysAvailable']);
     }
     if (array_key_exists('remoteId', $data)) {
         $contentCreateStruct->remoteId = $data['remoteId'];
     }
     if (array_key_exists('modificationDate', $data)) {
         $contentCreateStruct->modificationDate = new DateTime($data['modificationDate']);
     }
     if (array_key_exists('User', $data) && is_array($data['User'])) {
         if (!array_key_exists('_href', $data['User'])) {
             throw new Exceptions\Parser("Missing '_href' attribute for User element in ContentCreate.");
         }
         $contentCreateStruct->ownerId = $this->requestParser->parseHref($data['User']['_href'], 'userId');
     }
     if (!array_key_exists('fields', $data) || !is_array($data['fields']) || !is_array($data['fields']['field'])) {
         throw new Exceptions\Parser("Missing or invalid 'fields' element for ContentCreate.");
     }
     foreach ($data['fields']['field'] as $fieldData) {
         if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
             throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for ContentCreate.");
         }
         $fieldDefinition = $contentType->getFieldDefinition($fieldData['fieldDefinitionIdentifier']);
         if (!$fieldDefinition) {
             throw new Exceptions\Parser("'{$fieldData['fieldDefinitionIdentifier']}' is invalid field definition identifier for '{$contentType->identifier}' content type in ContentCreate.");
         }
         if (!array_key_exists('fieldValue', $fieldData)) {
             throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in ContentCreate.");
         }
         $fieldValue = $this->fieldTypeParser->parseValue($fieldDefinition->fieldTypeIdentifier, $fieldData['fieldValue']);
         $languageCode = null;
         if (array_key_exists('languageCode', $fieldData)) {
             $languageCode = $fieldData['languageCode'];
         }
         $contentCreateStruct->setField($fieldData['fieldDefinitionIdentifier'], $fieldValue, $languageCode);
     }
     return new RestContentCreateStruct($contentCreateStruct, $locationCreateStruct);
 }