コード例 #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;
 }
コード例 #2
0
 /**
  * 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();
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 /**
  * @inheritdoc
  */
 public function visit(TreeNodeInterface $node, &$data)
 {
     $struct = $this->contentTypeService->newFieldDefinitionCreateStruct('', '');
     $this->fillValueObject($struct, $data);
     // Get position from node index (starts from 1)
     $struct->position = $node->getIndex() + 1;
     return $struct;
 }
コード例 #7
0
ファイル: Version.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * 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);
 }
コード例 #8
0
 /**
  * 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);
 }
コード例 #9
0
 /**
  * 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]);
 }
コード例 #10
0
 protected function getSelectionChoices()
 {
     $contentTypeChoices = [];
     foreach ($this->contentTypeService->loadContentTypeGroups() as $group) {
         foreach ($this->contentTypeService->loadContentTypes($group) as $contentType) {
             $contentTypeChoices[$contentType->id] = $contentType->getName($contentType->mainLanguageCode);
         }
     }
     return $contentTypeChoices;
 }
コード例 #11
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('contentTypeGroupId', 'hidden', ['constraints' => new Callback(function ($contentTypeGroupId, ExecutionContextInterface $context) {
         try {
             $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId);
         } catch (NotFoundException $e) {
             $context->buildViolation('content_type.error.content_type_group.not_found')->setParameter('%id%', $contentTypeGroupId)->addViolation();
         }
     })])->add('create', 'submit', ['label' => 'content_type.create']);
 }
コード例 #12
0
 /**
  * @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]);
 }
コード例 #13
0
 /**
  * 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']));
 }
コード例 #14
0
 public function processUpdate(FormActionEvent $event)
 {
     /** @var \EzSystems\RepositoryForms\Data\ContentTypeGroup\ContentTypeGroupUpdateData|\EzSystems\RepositoryForms\Data\ContentTypeGroup\ContentTypeGroupCreateData $data */
     $data = $event->getData();
     if ($data->isNew()) {
         $contentTypeGroup = $this->contentTypeService->createContentTypeGroup($data);
     } else {
         $this->contentTypeService->updateContentTypeGroup($data->contentTypeGroup, $data);
         $contentTypeGroup = $this->contentTypeService->loadContentTypeGroup($data->getId());
     }
     $data->setContentTypeGroup($contentTypeGroup);
 }
コード例 #15
0
 /**
  * Parse input structure.
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeUpdateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     $contentTypeUpdateStruct = $this->contentTypeService->newContentTypeUpdateStruct();
     if (array_key_exists('identifier', $data)) {
         $contentTypeUpdateStruct->identifier = $data['identifier'];
     }
     if (array_key_exists('mainLanguageCode', $data)) {
         $contentTypeUpdateStruct->mainLanguageCode = $data['mainLanguageCode'];
     }
     if (array_key_exists('remoteId', $data)) {
         $contentTypeUpdateStruct->remoteId = $data['remoteId'];
     }
     if (array_key_exists('urlAliasSchema', $data)) {
         $contentTypeUpdateStruct->urlAliasSchema = $data['urlAliasSchema'];
     }
     if (array_key_exists('nameSchema', $data)) {
         $contentTypeUpdateStruct->nameSchema = $data['nameSchema'];
     }
     if (array_key_exists('isContainer', $data)) {
         $contentTypeUpdateStruct->isContainer = $this->parserTools->parseBooleanValue($data['isContainer']);
     }
     if (array_key_exists('defaultSortField', $data)) {
         $contentTypeUpdateStruct->defaultSortField = $this->parserTools->parseDefaultSortField($data['defaultSortField']);
     }
     if (array_key_exists('defaultSortOrder', $data)) {
         $contentTypeUpdateStruct->defaultSortOrder = $this->parserTools->parseDefaultSortOrder($data['defaultSortOrder']);
     }
     if (array_key_exists('defaultAlwaysAvailable', $data)) {
         $contentTypeUpdateStruct->defaultAlwaysAvailable = $this->parserTools->parseBooleanValue($data['defaultAlwaysAvailable']);
     }
     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 ContentTypeUpdate.");
         }
         $contentTypeUpdateStruct->names = $this->parserTools->parseTranslatableList($data['names']);
     }
     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 ContentTypeUpdate.");
         }
         $contentTypeUpdateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
     }
     if (array_key_exists('modificationDate', $data)) {
         $contentTypeUpdateStruct->modificationDate = new DateTime($data['modificationDate']);
     }
     if (array_key_exists('User', $data)) {
         if (!array_key_exists('_href', $data['User'])) {
             throw new Exceptions\Parser("Missing '_href' attribute for User element in ContentTypeUpdate.");
         }
         $contentTypeUpdateStruct->modifierId = $this->requestParser->parseHref($data['User']['_href'], 'userId');
     }
     return $contentTypeUpdateStruct;
 }
コード例 #16
0
 /**
  * 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]);
 }
コード例 #17
0
ファイル: User.php プロジェクト: CG77/ezpublish-kernel
 /**
  * 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);
 }
コード例 #18
0
 /**
  * @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);
 }
 /**
  * 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
     }
 }
コード例 #20
0
 /**
  * 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');
 }
コード例 #21
0
 /**
  * @return ContentType[]
  */
 protected function getContentTypeList()
 {
     $contentTypes = array();
     foreach ($this->contentTypeService->loadContentTypeGroups() as $contentTypeGroup) {
         $contentTypes = array_merge($contentTypes, $this->contentTypeService->loadContentTypes($contentTypeGroup));
     }
     return $contentTypes;
 }
コード例 #22
0
 public function processRemoveContentTypeDraft(FormActionEvent $event)
 {
     $contentTypeDraft = $event->getData()->contentTypeDraft;
     $this->contentTypeService->deleteContentType($contentTypeDraft);
     if (isset($this->options['redirectRouteAfterPublish'])) {
         $event->setResponse(new RedirectResponse($this->router->generate($this->options['redirectRouteAfterPublish'])));
     }
 }
コード例 #23
0
 /**
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup $contentTypeGroup
  */
 protected function assignContentGroupTypeToContentType($contentType, $contentTypeGroup)
 {
     try {
         $this->contentTypeService->assignContentTypeGroup($contentType, $contentTypeGroup);
     } catch (ApiExceptions\InvalidArgumentException $exception) {
         //do nothing
     }
 }
コード例 #24
0
 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');
 }
コード例 #25
0
 public function testIsFieldNotEmpty()
 {
     $contentTypeId = 123;
     $contentInfo = new ContentInfo(array('contentTypeId' => $contentTypeId));
     $content = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
     $content->expects($this->any())->method('__get')->with('contentInfo')->will($this->returnValue($contentInfo));
     $fieldDefIdentifier = 'my_field_definition';
     $textLineFT = new TextLineType();
     $nonEmptyValue = new Value('Vive le sucre !!!');
     $emptyField = new Field(array('fieldDefIdentifier' => 'ezstring', 'value' => $nonEmptyValue));
     $contentType = $this->getMockForAbstractClass('eZ\\Publish\\API\\Repository\\Values\\ContentType\\ContentType');
     $fieldDefinition = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\ContentType\\FieldDefinition')->setConstructorArgs(array(array('fieldTypeIdentifier' => 'ezstring')))->getMockForAbstractClass();
     $contentType->expects($this->once())->method('getFieldDefinition')->with($fieldDefIdentifier)->will($this->returnValue($fieldDefinition));
     $this->contentTypeServiceMock->expects($this->once())->method('loadContentType')->with($contentTypeId)->will($this->returnValue($contentType));
     $this->translationHelper->expects($this->once())->method('getTranslatedField')->with($content, $fieldDefIdentifier)->will($this->returnValue($emptyField));
     $this->fieldTypeServiceMock->expects($this->any())->method('getFieldType')->with('ezstring')->will($this->returnValue($textLineFT));
     $this->assertFalse($this->fieldHelper->isFieldEmpty($content, $fieldDefIdentifier));
 }
コード例 #26
0
 /**
  * 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];
 }
コード例 #27
0
 /**
  * Get content type groups from content type data
  *
  * @param array $data
  * @return array
  */
 private function getContentTypeGroups(array &$data)
 {
     $groupNames = [self::DEFAULT_GROUP_NAME];
     $groups = [];
     if (isset($data['groups'])) {
         $groupNames = $data['groups'];
     }
     foreach ($groupNames as $groupName) {
         $groups[] = $this->contentTypeService->loadContentTypeGroupByIdentifier($groupName);
     }
     return $groups;
 }
コード例 #28
0
 /**
  * Returns field definition by 'typeFieldDefinitionDraft' pattern URL.
  *
  * Assumes given $data array has '__url' element set.
  * @todo depends on temporary solution to give parser access to the URL
  * @see \eZ\Publish\Core\REST\Server\Controller\ContentType::updateFieldDefinition
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
  *
  * @param array $data
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition
  */
 protected function getFieldDefinition(array $data)
 {
     $contentTypeId = $this->requestParser->parseHref($data["__url"], 'contentTypeId');
     $fieldDefinitionId = $this->requestParser->parseHref($data["__url"], 'fieldDefinitionId');
     $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
     foreach ($contentTypeDraft->getFieldDefinitions() as $fieldDefinition) {
         if ($fieldDefinition->id == $fieldDefinitionId) {
             return $fieldDefinition;
         }
     }
     throw new Exceptions\NotFoundException("Field definition not found: '{$data["__url"]}'.");
 }
コード例 #29
0
 /**
  * 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));
 }
コード例 #30
0
 /**
  * Parse input structure
  *
  * @param array $data
  * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
  *
  * @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroupCreateStruct
  */
 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
 {
     // Since ContentTypeGroupInput is used both for creating and updating ContentTypeGroup and identifier is not
     // required when updating ContentTypeGroup, we need to rely on PAPI to throw the exception on missing
     // identifier when creating a ContentTypeGroup
     // @todo Bring in line with XSD which says that identifier is required always
     $contentTypeGroupIdentifier = null;
     if (array_key_exists('identifier', $data)) {
         $contentTypeGroupIdentifier = $data['identifier'];
     }
     $contentTypeGroupCreateStruct = $this->contentTypeService->newContentTypeGroupCreateStruct($contentTypeGroupIdentifier);
     if (array_key_exists('modificationDate', $data)) {
         $contentTypeGroupCreateStruct->creationDate = new DateTime($data['modificationDate']);
     }
     // @todo mainLanguageCode, names, descriptions?
     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 ContentTypeGroupInput.");
         }
         $contentTypeGroupCreateStruct->creatorId = $this->requestParser->parseHref($data['User']['_href'], 'userId');
     }
     return $contentTypeGroupCreateStruct;
 }