/**
  * Creates and prepares content create structure.
  *
  * @param array $data
  * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
  */
 private function getContentCreateStruct($data)
 {
     $contentType = $this->contentTypeService->loadContentTypeByIdentifier($data['content_type']);
     $struct = $this->contentService->newContentCreateStruct($contentType, '');
     $this->fillValueObject($struct, $data, ['content_type']);
     return $struct;
 }
Ejemplo n.º 2
0
 /**
  * @Given /^I set the Content to a User RestContentCreateStruct$/
  */
 public function iSetTheContentToUserContentCreateStruct()
 {
     $contentCreateStruct = $this->contentService->newContentCreateStruct($this->contentTypeService->loadContentTypeByIdentifier('user'), 'eng-GB');
     $userFieldValue = new UserValue(['login' => 'user_content_' . time(), 'email' => 'user_content_' . time() . '@example.com', 'passwordHash' => 'not_a_hash']);
     $contentCreateStruct->setField('first_name', new TextLineValue('User Content'));
     $contentCreateStruct->setField('last_name', new TextLineValue('@' . microtime(true)));
     $contentCreateStruct->setField('user_account', $userFieldValue);
     $restStruct = new RestContentCreateStruct($contentCreateStruct, new LocationCreateStruct(['parentLocationId' => 12]));
     $this->restContext->requestObject = $restStruct;
 }
 /**
  * Creates a content draft.
  *
  * @param eZ\Publish\API\Repository\Values\Content\Location $parentLocationId
  * @param string $contentTypeIdentifier
  * @param string $languageCode
  * @param array $fields Fields, as primitives understood by setField
  *
  * @return eZ\Publish\API\Repository\Values\Content\Content an unpublished Content draft
  */
 public function createContentDraft($parentLocationId, $contentTypeIdentifier, $fields, $languageCode = null)
 {
     $languageCode = $languageCode ?: self::DEFAULT_LANGUAGE;
     $repository = $this->getRepository();
     $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct($parentLocationId);
     $contentTypeIdentifier = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
     $contentCreateStruct = $this->contentService->newContentCreateStruct($contentTypeIdentifier, $languageCode);
     foreach (array_keys($fields) as $key) {
         $contentCreateStruct->setField($key, $fields[$key]);
     }
     return $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct));
 }
 /**
  * Instantiates a new content create struct object
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
  * @param string $mainLanguageCode
  *
  * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
  */
 public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)
 {
     return $this->service->newContentCreateStruct($contentType, $mainLanguageCode);
 }
Ejemplo n.º 5
-1
 /**
  * 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);
 }