/** * 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; }
/** * Parses input structure to a Criterion object * * @param array $data * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher * * @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser * * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId */ public function parse(array $data, ParsingDispatcher $parsingDispatcher) { if (!array_key_exists("ContentTypeIdentifierCriterion", $data)) { throw new Exceptions\Parser("Invalid <ContentTypeIdCriterion> format"); } $contentType = $this->contentTypeService->loadContentTypeByIdentifier($data["ContentTypeIdentifierCriterion"]); return new ContentTypeIdCriterion($contentType->id); }
/** * @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; }
/** * Parses input structure to a Criterion object. * * @param array $data * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher * * @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser * * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId */ public function parse(array $data, ParsingDispatcher $parsingDispatcher) { if (!array_key_exists('ContentTypeIdentifierCriterion', $data)) { throw new Exceptions\Parser('Invalid <ContentTypeIdCriterion> format'); } if (!is_array($data['ContentTypeIdentifierCriterion'])) { $data['ContentTypeIdentifierCriterion'] = [$data['ContentTypeIdentifierCriterion']]; } return new ContentTypeIdCriterion(array_map(function ($contentTypeIdentifier) { return $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier)->id; }, $data['ContentTypeIdentifierCriterion'])); }
/** * Update content type definition and returns a draft * * @param array $data * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft */ private function getUpdatedDraft(array &$data) { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($data['identifier']); $draft = $this->contentTypeService->createContentTypeDraft($contentType); // Update content type $struct = $this->contentTypeService->newContentTypeUpdateStruct($data); $this->fillValueObject($struct, $data); $diff = $this->diff->diff($contentType->fieldDefinitions, $data['field_definitions'], 'identifier'); // @todo: introduce field updates (now only remove and add are supported) $this->updateDraftFields($draft, $diff, $data); $this->contentTypeService->updateContentTypeDraft($draft, $struct); return $draft; }
/** * Displays and processes a content creation form. Showing the form does not create a draft in the repository. * * @param int $contentTypeIdentifier ContentType id to create * @param string $language Language code to create the content in (eng-GB, ger-DE, ...)) * @param int $parentLocationId Location the content should be a child of * @param \Symfony\Component\HttpFoundation\Request $request * * @return \Symfony\Component\HttpFoundation\Response */ public function createWithoutDraftAction($contentTypeIdentifier, $language, $parentLocationId, Request $request) { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); $data = (new ContentCreateMapper())->mapToFormData($contentType, ['mainLanguageCode' => $language, 'parentLocation' => $this->locationService->newLocationCreateStruct($parentLocationId)]); $form = $this->createForm(ContentEditType::class, $data, ['languageCode' => $language]); $form->handleRequest($request); if ($form->isValid()) { $this->contentActionDispatcher->dispatchFormAction($form, $data, $form->getClickedButton()->getName()); if ($response = $this->contentActionDispatcher->getResponse()) { return $response; } } return $this->render('EzSystemsRepositoryFormsBundle:Content:content_edit.html.twig', ['form' => $form->createView(), 'languageCode' => $language, 'pagelayout' => $this->pagelayout]); }
/** * Checks if the passed value is valid. * * @param ContentTypeData $value The value that should be validated * @param Constraint|UniqueFieldDefinitionIdentifier $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { if (!$value instanceof ContentTypeData) { return; } try { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($value->identifier); // It's of course OK to edit a draft of an existing ContentType :-) if ($contentType->id === $value->contentTypeDraft->id) { return; } $this->context->buildViolation($constraint->message)->atPath('identifier')->setParameter('%identifier%', $value->identifier)->addViolation(); } catch (NotFoundException $e) { // Do nothing } }
public function updateFieldDefinition($identifier, FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct) { $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($this->currentContentType); $this->contentTypeService->updateFieldDefinition($contentTypeDraft, $this->currentContentType->getFieldDefinition($identifier), $fieldDefinitionUpdateStruct); $this->contentTypeService->publishContentTypeDraft($contentTypeDraft); $this->currentContentType = $this->contentTypeService->loadContentTypeByIdentifier($this->currentContentType->identifier); }
/** * 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)); }
/** * Load and return a content type by its identifier. * * @param string $identifier content type identifier * @param bool $throwIfNotFound if true, throws an exception if it is not found. * * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup|null */ protected function loadContentTypeByIdentifier($identifier, $throwIfNotFound = true) { $contentType = null; try { $contentType = $this->contentTypeService->loadContentTypeByIdentifier($identifier); } catch (ApiExceptions\NotFoundException $e) { $notFoundException = $e; } if (!$contentType && $throwIfNotFound) { throw $notFoundException; } return $contentType; }
/** * Get a Content Type object by identifier * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If content type with the given identifier and status DEFINED can not be found * * @param string $identifier * * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType */ public function loadContentTypeByIdentifier($identifier) { return $this->service->loadContentTypeByIdentifier($identifier); }
/** * Returns ContentType ID based on $contentType name. * * @param string $contentType * * @return int */ protected function getContentTypeId($contentType) { return $this->contentTypeService->loadContentTypeByIdentifier($contentType)->id; }
/** * Loads a content type by its identifier * * @return \eZ\Publish\API\Repository\Values\ContentType\ContentType */ public function loadContentTypeByIdentifier(Request $request) { return $this->contentTypeService->loadContentTypeByIdentifier($request->query->get('identifier')); }