Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

FieldDefinitionUpdate.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Input\Parser;
8
9 use eZ\Publish\Core\REST\Common\Input\BaseParser;
10 use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
11 use eZ\Publish\Core\REST\Common\Input\FieldTypeParser;
12 use eZ\Publish\Core\REST\Common\Input\ParserTools;
13 use eZ\Publish\API\Repository\ContentTypeService;
14 use eZ\Publish\Core\REST\Common\Exceptions;
15
19 class FieldDefinitionUpdate extends BaseParser
20 {
26 protected $contentTypeService;
27
33 protected $fieldTypeParser;
34
40 protected $parserTools;
41
48 public function __construct(ContentTypeService $contentTypeService, FieldTypeParser $fieldTypeParser, ParserTools $parserTools)
49 {
50 $this->contentTypeService = $contentTypeService;
51 $this->fieldTypeParser = $fieldTypeParser;
52 $this->parserTools = $parserTools;
53 }
54
63 public function parse(array $data, ParsingDispatcher $parsingDispatcher)
64 {
65 $fieldDefinitionUpdate = $this->contentTypeService->newFieldDefinitionUpdateStruct();
66
67 if (array_key_exists('identifier', $data)) {
68 $fieldDefinitionUpdate->identifier = $data['identifier'];
69 }
70
71 // @todo XSD says that descriptions is mandatory, but field definition can be updated without it
72 if (array_key_exists('names', $data)) {
73 if (!is_array($data['names']) || !array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
74 throw new Exceptions\Parser("Invalid 'names' element for FieldDefinitionUpdate.");
75 }
76
77 $fieldDefinitionUpdate->names = $this->parserTools->parseTranslatableList($data['names']);
78 }
79
80 // @todo XSD says that descriptions is mandatory, but field definition can be updated without it
81 if (array_key_exists('descriptions', $data)) {
82 if (!is_array($data['descriptions']) || !array_key_exists('value', $data['descriptions']) || !is_array($data['descriptions']['value'])) {
83 throw new Exceptions\Parser("Invalid 'descriptions' element for FieldDefinitionUpdate.");
84 }
85
86 $fieldDefinitionUpdate->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
87 }
88
89 // @todo XSD says that fieldGroup is mandatory, but field definition can be updated without it
90 if (array_key_exists('fieldGroup', $data)) {
91 $fieldDefinitionUpdate->fieldGroup = $data['fieldGroup'];
92 }
93
94 // @todo XSD says that position is mandatory, but field definition can be updated without it
95 if (array_key_exists('position', $data)) {
96 $fieldDefinitionUpdate->position = (int)$data['position'];
97 }
98
99 // @todo XSD says that isTranslatable is mandatory, but field definition can be updated without it
100 if (array_key_exists('isTranslatable', $data)) {
101 $fieldDefinitionUpdate->isTranslatable = $this->parserTools->parseBooleanValue($data['isTranslatable']);
102 }
103
104 // @todo XSD says that isRequired is mandatory, but field definition can be updated without it
105 if (array_key_exists('isRequired', $data)) {
106 $fieldDefinitionUpdate->isRequired = $this->parserTools->parseBooleanValue($data['isRequired']);
107 }
108
109 // @todo XSD says that isInfoCollector is mandatory, but field definition can be updated without it
110 if (array_key_exists('isInfoCollector', $data)) {
111 $fieldDefinitionUpdate->isInfoCollector = $this->parserTools->parseBooleanValue($data['isInfoCollector']);
112 }
113
114 // @todo XSD says that isSearchable is mandatory, but field definition can be updated without it
115 if (array_key_exists('isSearchable', $data)) {
116 $fieldDefinitionUpdate->isSearchable = $this->parserTools->parseBooleanValue($data['isSearchable']);
117 }
118
119 $fieldDefinition = $this->getFieldDefinition($data);
120
121 // @todo XSD says that defaultValue is mandatory, but content type can be created without it
122 if (array_key_exists('defaultValue', $data)) {
123 $fieldDefinitionUpdate->defaultValue = $this->fieldTypeParser->parseValue(
124 $fieldDefinition->fieldTypeIdentifier,
125 $data['defaultValue']
126 );
127 }
128
129 if (array_key_exists('validatorConfiguration', $data)) {
130 $fieldDefinitionUpdate->validatorConfiguration = $this->fieldTypeParser->parseValidatorConfiguration(
131 $fieldDefinition->fieldTypeIdentifier,
132 $data['validatorConfiguration']
133 );
134 }
135
136 if (array_key_exists('fieldSettings', $data)) {
137 $fieldDefinitionUpdate->fieldSettings = $this->fieldTypeParser->parseFieldSettings(
138 $fieldDefinition->fieldTypeIdentifier,
139 $data['fieldSettings']
140 );
141 }
142
143 return $fieldDefinitionUpdate;
144 }
145
161 protected function getFieldDefinition(array $data)
162 {
163 $contentTypeId = $this->requestParser->parseHref($data['__url'], 'contentTypeId');
164 $fieldDefinitionId = $this->requestParser->parseHref($data['__url'], 'fieldDefinitionId');
165
166 $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
167 foreach ($contentTypeDraft->getFieldDefinitions() as $fieldDefinition) {
168 if ($fieldDefinition->id == $fieldDefinitionId) {
169 return $fieldDefinition;
170 }
171 }
172 throw new Exceptions\NotFoundException("Field definition not found: '{$data['__url']}'.");
173 }
174 }
eZ\Publish\Core\REST\Common\Input\BaseParser
Definition: BaseParser.php:12
eZ\Publish\Core\REST\Common\Input\FieldTypeParser
Definition: FieldTypeParser.php:15
eZ\Publish\Core\REST\Common\Input\ParserTools
Tools object to be used in Input Parsers.
Definition: ParserTools.php:17
eZ\Publish\Core\REST\Common\Input\ParsingDispatcher
Parsing dispatcher.
Definition: ParsingDispatcher.php:15
eZ\Publish\Core\REST\Server\Input\Parser\FieldDefinitionUpdate
Parser for FieldDefinitionUpdate.
Definition: FieldDefinitionUpdate.php:20
eZ\Publish\Core\REST\Server\Input\Parser\FieldDefinitionUpdate\__construct
__construct(ContentTypeService $contentTypeService, FieldTypeParser $fieldTypeParser, ParserTools $parserTools)
Construct.
Definition: FieldDefinitionUpdate.php:48
eZ\Publish\Core\REST\Server\Input\Parser\FieldDefinitionUpdate\parse
parse(array $data, ParsingDispatcher $parsingDispatcher)
Parse input structure.
Definition: FieldDefinitionUpdate.php:63
eZ\Publish\Core\REST\Server\Input\Parser\FieldDefinitionUpdate\getFieldDefinition
getFieldDefinition(array $data)
Returns field definition by 'typeFieldDefinitionDraft' pattern URL.
Definition: FieldDefinitionUpdate.php:161
eZ\Publish\Core\REST\Server\Input\Parser\FieldDefinitionUpdate\$fieldTypeParser
$fieldTypeParser
Definition: FieldDefinitionUpdate.php:33
eZ\Publish\Core\REST\Server\Input\Parser\FieldDefinitionUpdate\$parserTools
$parserTools
Definition: FieldDefinitionUpdate.php:40
eZ\Publish\Core\REST\Server\Input\Parser\FieldDefinitionUpdate\$contentTypeService
$contentTypeService
Definition: FieldDefinitionUpdate.php:26
eZ\Publish\API\Repository\ContentTypeService
Definition: API/Repository/ContentTypeService.php:25
eZ\Publish\Core\REST\Common\Exceptions
Definition: Core/REST/Common/Exceptions/ForbiddenException.php:7
eZ\Publish\Core\REST\Server\Input\Parser
Definition: ContentCreate.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.