本文整理汇总了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);
}
示例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);
}
示例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);
}
}
}
示例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()}'.");
}
示例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;
}