/**
  * 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;
 }
 /**
  * Returns form handler to use at $location
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $location
  * @return \Heliopsis\eZFormsBundle\FormHandler\FormHandlerInterface
  */
 public function getHandler(Location $location)
 {
     $locationContentTypeId = $location->contentInfo->contentTypeId;
     /** @var ContentType $locationContentType */
     $locationContentType = $this->contentTypeService->loadContentType($locationContentTypeId);
     return array_key_exists($locationContentType->identifier, $this->map) ? $this->map[$locationContentType->identifier] : new NullHandler();
 }
 /**
  * Parses the given $value for the field $fieldDefIdentifier in the content
  * identified by $contentInfoId.
  *
  * @param string $contentInfoId
  * @param string $fieldDefIdentifier
  * @param mixed $value
  *
  * @return mixed
  */
 public function parseFieldValue($contentInfoId, $fieldDefIdentifier, $value)
 {
     $contentInfo = $this->contentService->loadContentInfo($contentInfoId);
     $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
     $fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier);
     return $this->parseValue($fieldDefinition->fieldTypeIdentifier, $value);
 }
Exemple #4
0
 /**
  * Parse input structure.
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\Core\REST\Server\Values\Version
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     $contentId = $this->requestParser->parseHref($data['VersionInfo']['Content']['_href'], 'contentId');
     $content = $this->contentService->loadContent($contentId, null, $data['VersionInfo']['versionNo']);
     $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
     $relations = $this->contentService->loadRelations($content->versionInfo);
     return new VersionValue($content, $contentType, $relations);
 }
 /**
  * Maps Repository ContentInfo to the Site ContentInfo.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
  * @param string $languageCode
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
  *
  * @return \Netgen\EzPlatformSiteApi\API\Values\ContentInfo
  */
 public function mapContentInfo(VersionInfo $versionInfo, $languageCode, ContentType $contentType = null)
 {
     $contentInfo = $versionInfo->contentInfo;
     if ($contentType === null) {
         $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
     }
     return new ContentInfo(['name' => $versionInfo->getName($languageCode), 'languageCode' => $languageCode, 'innerContentInfo' => $versionInfo->contentInfo, 'innerContentType' => $contentType]);
 }
 /**
  * @param Location $location
  * @return \Symfony\Component\Form\FormInterface
  * @throws \Heliopsis\eZFormsBundle\Exceptions\UnknownFormException
  */
 public function getForm(Location $location)
 {
     $locationContentTypeId = $location->contentInfo->contentTypeId;
     /** @var ContentType $locationContentType */
     $locationContentType = $this->contentTypeService->loadContentType($locationContentTypeId);
     if (!array_key_exists($locationContentType->identifier, $this->map)) {
         throw new UnknownFormException(sprintf("No form could be mapped to content type identifier '%s'", $locationContentType->identifier));
     }
     return $this->formFactory->create($this->map[$locationContentType->identifier]);
 }
 /**
  * @Given /^it contains a Version of ContentType "([^"]*)"$/
  */
 public function itContainsAVersionOfContentType($contentTypeIdentifier)
 {
     $object = $this->restContext->getResponseObject();
     Assertion::assertInstanceOf('eZ\\Publish\\Core\\REST\\Server\\Values\\Version', $object);
     Assertion::assertEquals($contentTypeIdentifier, $this->contentTypeService->loadContentType($object->content->contentInfo->contentTypeId)->identifier);
     $this->currentContent = $this->contentService->loadContentByVersionInfo($object->content->versionInfo);
 }
Exemple #8
0
 /**
  * Assigns the user to a user group
  *
  * @param $userId
  *
  * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
  * @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
  */
 public function assignUserToUserGroup($userId)
 {
     $user = $this->userService->loadUser($userId);
     try {
         $userGroupLocation = $this->locationService->loadLocation($this->extractLocationIdFromPath($this->request->query->get('group')));
     } catch (APINotFoundException $e) {
         throw new Exceptions\ForbiddenException($e->getMessage());
     }
     try {
         $userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId);
     } catch (APINotFoundException $e) {
         throw new Exceptions\ForbiddenException($e->getMessage());
     }
     try {
         $this->userService->assignUserToUserGroup($user, $userGroup);
     } catch (InvalidArgumentException $e) {
         throw new Exceptions\ForbiddenException($e->getMessage());
     }
     $userGroups = $this->userService->loadUserGroupsOfUser($user);
     $restUserGroups = array();
     foreach ($userGroups as $userGroup) {
         $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
         $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
         $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
         $restUserGroups[] = new Values\RestUserGroup($userGroup, $contentType, $userGroupContentInfo, $userGroupLocation, $this->contentService->loadRelations($userGroup->getVersionInfo()));
     }
     return new Values\UserGroupRefList($restUserGroups, $this->router->generate('ezpublish_rest_loadUserGroupsOfUser', array('userId' => $userId)), $userId);
 }
 /**
  * Visit struct returned by controllers.
  *
  * @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
  * @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
  * @param \eZ\Publish\Core\REST\Server\Values\RestExecutedView $data
  */
 public function visit(Visitor $visitor, Generator $generator, $data)
 {
     $generator->startObjectElement('View');
     $visitor->setHeader('Content-Type', $generator->getMediaType('View'));
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_views_load', array('viewId' => $data->identifier)));
     $generator->endAttribute('href');
     $generator->startValueElement('identifier', $data->identifier);
     $generator->endValueElement('identifier');
     // BEGIN Query
     $generator->startObjectElement('Query');
     $generator->endObjectElement('Query');
     // END Query
     // BEGIN Result
     $generator->startObjectElement('Result', 'ViewResult');
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_views_load_results', array('viewId' => $data->identifier)));
     $generator->endAttribute('href');
     // BEGIN Result metadata
     $generator->startValueElement('count', $data->searchResults->totalCount);
     $generator->endValueElement('count');
     $generator->startValueElement('time', $data->searchResults->time);
     $generator->endValueElement('time');
     $generator->startValueElement('timedOut', $generator->serializeBool($data->searchResults->timedOut));
     $generator->endValueElement('timedOut');
     $generator->startValueElement('maxScore', $data->searchResults->maxScore);
     $generator->endValueElement('maxScore');
     // END Result metadata
     // BEGIN searchHits
     $generator->startHashElement('searchHits');
     $generator->startList('searchHit');
     foreach ($data->searchResults->searchHits as $searchHit) {
         $generator->startObjectElement('searchHit');
         $generator->startAttribute('score', 0);
         $generator->endAttribute('score');
         $generator->startAttribute('index', 0);
         $generator->endAttribute('index');
         $generator->startObjectElement('value');
         // @todo Refactor
         if ($searchHit->valueObject instanceof ApiValues\Content) {
             /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
             $contentInfo = $searchHit->valueObject->contentInfo;
             $valueObject = new RestContentValue($contentInfo, $this->locationService->loadLocation($contentInfo->mainLocationId), $searchHit->valueObject, $this->contentTypeService->loadContentType($contentInfo->contentTypeId), $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo()));
         } elseif ($searchHit->valueObject instanceof ApiValues\Location) {
             $valueObject = $searchHit->valueObject;
         } elseif ($searchHit->valueObject instanceof ApiValues\ContentInfo) {
             $valueObject = new RestContentValue($searchHit->valueObject);
         } else {
             throw new Exceptions\InvalidArgumentException('Unhandled object type');
         }
         $visitor->visitValueObject($valueObject);
         $generator->endObjectElement('value');
         $generator->endObjectElement('searchHit');
     }
     $generator->endList('searchHit');
     $generator->endHashElement('searchHits');
     // END searchHits
     $generator->endObjectElement('Result');
     // END Result
     $generator->endObjectElement('View');
 }
 public function processRemoveContentTypeDraft(FormActionEvent $event)
 {
     /** @var ContentTypeDraft $contentTypeDraft */
     $contentTypeDraft = $event->getData()->contentTypeDraft;
     $languageCode = $event->getOption('languageCode');
     // Redirect response will be different if we're dealing with an existing ContentType or a newly created one, which has been discarded.
     try {
         // This will throw a NotFoundException if a published version doesn't exist for this ContentType.
         $this->contentTypeService->loadContentType($contentTypeDraft->id);
         $response = $this->generateRedirectResponse($contentTypeDraft, $languageCode);
     } catch (NotFoundException $e) {
         // ContentTypeDraft was newly created, but then discarded.
         // Redirect to the ContentTypeGroup view.
         $response = new FormProcessingDoneResponse($this->router->generate('admin_contenttypeGroupView', ['contentTypeGroupId' => $contentTypeDraft->contentTypeGroups[0]->id]));
     }
     $event->setResponse($response);
     $this->notify('content_type.notification.draft_removed', [], 'content_type');
 }
 /**
  * Returns the field type identifier for $field.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Content $content
  * @param \eZ\Publish\API\Repository\Values\Content\Field $field
  *
  * @return string
  */
 private function getFieldTypeIdentifier(Content $content, Field $field)
 {
     $contentInfo = $content->getVersionInfo()->getContentInfo();
     $key = $contentInfo->contentTypeId . '  ' . $field->fieldDefIdentifier;
     if (!isset($this->fieldTypeIdentifiers[$key])) {
         $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
         $this->fieldTypeIdentifiers[$key] = $contentType->getFieldDefinition($field->fieldDefIdentifier)->fieldTypeIdentifier;
     }
     return $this->fieldTypeIdentifiers[$key];
 }
 public function deleteContentTypeAction(Request $request, $contentTypeId)
 {
     $contentType = $this->contentTypeService->loadContentType($contentTypeId);
     $deleteForm = $this->createForm(new ContentTypeDeleteType(), ['contentTypeId' => $contentTypeId]);
     $deleteForm->handleRequest($request);
     if ($deleteForm->isValid()) {
         $this->contentTypeService->deleteContentType($contentType);
         $this->notify('content_type.notification.deleted', ['%contentTypeName%' => $contentType->getName($contentType->mainLanguageCode)], 'content_type');
         return $this->redirectToRouteAfterFormPost('admin_contenttypeGroupView', ['contentTypeGroupId' => $contentType->getContentTypeGroups()[0]->id]);
     }
     // Form validation failed. Send errors as notifications.
     foreach ($deleteForm->getErrors(true) as $error) {
         $this->notifyErrorPlural($error->getMessageTemplate(), $error->getMessagePluralization(), $error->getMessageParameters(), 'ezrepoforms_content_type');
     }
     return $this->redirectToRouteAfterFormPost('admin_contenttypeView', ['contentTypeId' => $contentTypeId]);
 }
 /**
  * Return identifier of a field of ezimage type.
  *
  * @param mixed $contentId
  * @param string $language
  * @param bool $related
  *
  * @return string
  */
 private function getImageFieldIdentifier($contentId, $language, $related = false)
 {
     $content = $this->contentService->loadContent($contentId);
     $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
     $fieldDefinitions = $this->getFieldDefinitionList();
     $fieldNames = array_flip($fieldDefinitions);
     if (in_array('ezimage', $fieldDefinitions)) {
         return $fieldNames['ezimage'];
     } elseif (in_array('ezobjectrelation', $fieldDefinitions) && !$related) {
         $field = $content->getFieldValue($fieldNames['ezobjectrelation'], $language);
         if (!empty($field->destinationContentId)) {
             return $this->getImageFieldIdentifier($field->destinationContentId, $language, true);
         }
     } else {
         return $this->getConfiguredFieldIdentifier('image', $contentType);
     }
 }
 /**
  * Visit struct returned by controllers
  *
  * @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
  * @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
  * @param \eZ\Publish\Core\REST\Server\Values\RestExecutedView $data
  */
 public function visit(Visitor $visitor, Generator $generator, $data)
 {
     $generator->startObjectElement('View');
     $visitor->setHeader('Content-Type', $generator->getMediaType('View'));
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_getView', array('viewId' => $data->identifier)));
     $generator->endAttribute('href');
     $generator->startValueElement('identifier', $data->identifier);
     $generator->endValueElement('identifier');
     // BEGIN Query
     $generator->startObjectElement('Query');
     $generator->endObjectElement('Query');
     // END Query
     // BEGIN Result
     $generator->startObjectElement('Result', 'ViewResult');
     $generator->startAttribute('href', $this->router->generate('ezpublish_rest_loadViewResults', array('viewId' => $data->identifier)));
     $generator->endAttribute('href');
     // BEGIN searchHits
     $generator->startHashElement('searchHits');
     $generator->startList('searchHit');
     foreach ($data->searchResults->searchHits as $searchHit) {
         $generator->startObjectElement('searchHit');
         $generator->startAttribute('score', 0);
         $generator->endAttribute('score');
         $generator->startAttribute('index', 0);
         $generator->endAttribute('index');
         $generator->startObjectElement('value');
         /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo */
         $contentInfo = $searchHit->valueObject->contentInfo;
         $restContent = new RestContentValue($contentInfo, $this->locationService->loadLocation($contentInfo->mainLocationId), $searchHit->valueObject, $this->contentTypeService->loadContentType($contentInfo->contentTypeId), $this->contentService->loadRelations($searchHit->valueObject->getVersionInfo()));
         $visitor->visitValueObject($restContent);
         $generator->endObjectElement('value');
         $generator->endObjectElement('searchHit');
     }
     $generator->endList('searchHit');
     $generator->endHashElement('searchHits');
     // END searchHits
     $generator->endObjectElement('Result');
     // END Result
     $generator->endObjectElement('View');
 }
 /**
  * Removes the given group from the content type and returns the updated group list
  *
  * @param $contentTypeId
  * @param $contentTypeGroupId
  *
  * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
  * @throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException
  * @return \eZ\Publish\Core\REST\Server\Values\ContentTypeGroupRefList
  */
 public function unlinkContentTypeFromGroup($contentTypeId, $contentTypeGroupId)
 {
     $contentType = $this->contentTypeService->loadContentType($contentTypeId);
     $contentTypeGroup = $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId);
     $existingContentTypeGroups = $contentType->getContentTypeGroups();
     $contentTypeInGroup = false;
     foreach ($existingContentTypeGroups as $existingGroup) {
         if ($existingGroup->id == $contentTypeGroup->id) {
             $contentTypeInGroup = true;
             break;
         }
     }
     if (!$contentTypeInGroup) {
         throw new Exceptions\NotFoundException('Content type is not in the given group');
     }
     if (count($existingContentTypeGroups) == 1) {
         throw new ForbiddenException('Content type cannot be unlinked from the only remaining group');
     }
     $this->contentTypeService->unassignContentTypeGroup($contentType, $contentTypeGroup);
     $contentType = $this->contentTypeService->loadContentType($contentTypeId);
     return new Values\ContentTypeGroupRefList($contentType, $contentType->getContentTypeGroups());
 }
 /**
  * Get a Content Type object by id
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If a content type with the given id and status DEFINED can not be found
  *
  * @param mixed $contentTypeId
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType
  */
 public function loadContentType($contentTypeId)
 {
     return $this->service->loadContentType($contentTypeId);
 }
 /**
  * Returns ContentType identifier based on $contentId.
  *
  * @param int|mixed $contentId
  *
  * @return string
  */
 private function getContentIdentifier($contentId)
 {
     $contentType = $this->contentTypeService->loadContentType($this->contentService->loadContent($contentId)->contentInfo->contentTypeId);
     return $contentType->identifier;
 }
 /**
  * Returns tracking category name by locationId.
  *
  * @param int $locationId
  *
  * @return null|string
  */
 public function getCategoryByLocationId($locationId)
 {
     $location = $this->locationService->loadLocation($locationId);
     $contentType = $this->contentTypeService->loadContentType($location->getContentInfo()->contentTypeId);
     return $this->getCategoryByContentTypeIdentifier($contentType->identifier);
 }
 /**
  * Returns FieldDefinition object based on $contentInfo and $fieldDefIdentifier.
  *
  * @param ContentInfo $contentInfo
  * @param string $fieldDefIdentifier
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition
  */
 public function getFieldDefinition(ContentInfo $contentInfo, $fieldDefIdentifier)
 {
     return $this->contentTypeService->loadContentType($contentInfo->contentTypeId)->getFieldDefinition($fieldDefIdentifier);
 }
 /**
  * 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);
 }