當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ContentTypeService::addFieldDefinition方法代碼示例

本文整理匯總了PHP中eZ\Publish\API\Repository\ContentTypeService::addFieldDefinition方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContentTypeService::addFieldDefinition方法的具體用法?PHP ContentTypeService::addFieldDefinition怎麽用?PHP ContentTypeService::addFieldDefinition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在eZ\Publish\API\Repository\ContentTypeService的用法示例。


在下文中一共展示了ContentTypeService::addFieldDefinition方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: processAddFieldDefinition

 public function processAddFieldDefinition(FormActionEvent $event)
 {
     $contentTypeDraft = $event->getData()->contentTypeDraft;
     $fieldTypeIdentifier = $event->getForm()->get('fieldTypeSelection')->getData();
     $fieldDefCreateStruct = new FieldDefinitionCreateStruct(['fieldTypeIdentifier' => $fieldTypeIdentifier, 'identifier' => sprintf('new_%s_%d', $fieldTypeIdentifier, count($contentTypeDraft->fieldDefinitions) + 1), 'names' => [$event->getOption('languageCode') => 'New FieldDefinition']]);
     $this->contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreateStruct);
 }
開發者ID:asfram,項目名稱:repository-forms,代碼行數:7,代碼來源:ContentTypeFormProcessor.php

示例2: processAddFieldDefinition

 public function processAddFieldDefinition(FormActionEvent $event)
 {
     // Reload the draft, to make sure we include any changes made in the current form submit
     $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($event->getData()->contentTypeDraft->id);
     $fieldTypeIdentifier = $event->getForm()->get('fieldTypeSelection')->getData();
     $maxFieldPos = 0;
     foreach ($contentTypeDraft->fieldDefinitions as $existingFieldDef) {
         if ($existingFieldDef->position > $maxFieldPos) {
             $maxFieldPos = $existingFieldDef->position;
         }
     }
     $fieldDefCreateStruct = new FieldDefinitionCreateStruct(['fieldTypeIdentifier' => $fieldTypeIdentifier, 'identifier' => sprintf('new_%s_%d', $fieldTypeIdentifier, count($contentTypeDraft->fieldDefinitions) + 1), 'names' => [$event->getOption('languageCode') => 'New FieldDefinition'], 'position' => $maxFieldPos + 1]);
     $this->contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefCreateStruct);
 }
開發者ID:crevillo,項目名稱:repository-forms,代碼行數:14,代碼來源:ContentTypeFormProcessor.php

示例3: updateDraftFields

 /**
  * Update draft fields with diff data
  *
  * @param ContentTypeDraft $draft
  * @param array $diff
  * @param array $data
  */
 private function updateDraftFields(ContentTypeDraft $draft, array $diff, array &$data)
 {
     // Remove fields which are missing in the new definition
     foreach ($draft->fieldDefinitions as $fieldDefinition) {
         if (in_array($fieldDefinition->identifier, $diff['remove'])) {
             $this->contentTypeService->removeFieldDefinition($draft, $fieldDefinition);
         }
     }
     // Add fields which are missing in the old content type
     $fieldStructs = $data['field_definitions'];
     //$this->getFieldDefinitionCreateStructs($data);
     foreach ($fieldStructs as $fieldStruct) {
         if (in_array($fieldStruct->identifier, $diff['add'])) {
             $this->contentTypeService->addFieldDefinition($draft, $fieldStruct);
         }
     }
 }
開發者ID:silversolutions,項目名稱:content-loader-bundle,代碼行數:24,代碼來源:ContentType.php

示例4: addContentTypeDraftFieldDefinition

 /**
  * Creates a new field definition for the given content type draft
  *
  * @param $contentTypeId
  *
  * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
  * @throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException
  * @return \eZ\Publish\Core\REST\Server\Values\CreatedFieldDefinition
  */
 public function addContentTypeDraftFieldDefinition($contentTypeId, Request $request)
 {
     $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
     $fieldDefinitionCreate = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
     try {
         $this->contentTypeService->addFieldDefinition($contentTypeDraft, $fieldDefinitionCreate);
     } catch (InvalidArgumentException $e) {
         throw new ForbiddenException($e->getMessage());
     } catch (ContentTypeFieldDefinitionValidationException $e) {
         throw new BadRequestException($e->getMessage());
     } catch (BadStateException $e) {
         throw new ForbiddenException($e->getMessage());
     }
     $updatedDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
     foreach ($updatedDraft->getFieldDefinitions() as $fieldDefinition) {
         if ($fieldDefinition->identifier == $fieldDefinitionCreate->identifier) {
             return new Values\CreatedFieldDefinition(array('fieldDefinition' => new Values\RestFieldDefinition($updatedDraft, $fieldDefinition)));
         }
     }
     throw new Exceptions\NotFoundException("Field definition not found: '{$request->getPathInfo()}'.");
 }
開發者ID:nlescure,項目名稱:ezpublish-kernel,代碼行數:30,代碼來源:ContentType.php

示例5: addFieldDefinition

 /**
  * Adds a new field definition to an existing content type.
  *
  * The content type must be in state DRAFT.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier in already exists in the content type
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit a content type
  * @throws \eZ\Publish\API\Repository\Exceptions\ContentTypeFieldDefinitionValidationException
  *         if a field definition in the $contentTypeCreateStruct is not valid
  * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If field definition of the same non-repeatable type is being
  *                                                                 added to the ContentType that already contains one
  *                                                                 or field definition that can't be added to a ContentType that
  *                                                                 has Content instances is being added to such ContentType
  *
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft $contentTypeDraft
  * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct $fieldDefinitionCreateStruct
  */
 public function addFieldDefinition(ContentTypeDraft $contentTypeDraft, FieldDefinitionCreateStruct $fieldDefinitionCreateStruct)
 {
     $returnValue = $this->service->addFieldDefinition($contentTypeDraft, $fieldDefinitionCreateStruct);
     $this->signalDispatcher->emit(new AddFieldDefinitionSignal(array('contentTypeDraftId' => $contentTypeDraft->id)));
     return $returnValue;
 }
開發者ID:Jenkosama,項目名稱:ezpublish-kernel,代碼行數:23,代碼來源:ContentTypeService.php


注:本文中的eZ\Publish\API\Repository\ContentTypeService::addFieldDefinition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。