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

Output/ValueObjectVisitor/RestFieldDefinition.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
8
9 use eZ\Publish\Core\REST\Common\Output\Generator;
10 use eZ\Publish\Core\REST\Common\Output\Visitor;
11 use eZ\Publish\Core\REST\Common\Output\FieldTypeSerializer;
12 use eZ\Publish\API\Repository\Values\ContentType\ContentType as APIContentType;
13
19 class RestFieldDefinition extends RestContentTypeBase
20 {
22 protected $fieldTypeSerializer;
23
27 public function __construct(FieldTypeSerializer $fieldTypeSerializer)
28 {
29 $this->fieldTypeSerializer = $fieldTypeSerializer;
30 }
31
39 public function visit(Visitor $visitor, Generator $generator, $data)
40 {
41 $restFieldDefinition = $data;
42 $fieldDefinition = $restFieldDefinition->fieldDefinition;
43 $contentType = $restFieldDefinition->contentType;
44
45 $urlTypeSuffix = $this->getUrlTypeSuffix($contentType->status);
46
47 $generator->startObjectElement('FieldDefinition');
48 $visitor->setHeader('Content-Type', $generator->getMediaType('FieldDefinition'));
49
50 if ($contentType->status === APIContentType::STATUS_DRAFT) {
51 $visitor->setHeader('Accept-Patch', $generator->getMediaType('FieldDefinitionUpdate'));
52 }
53
54 $generator->startAttribute(
55 'href',
56 $this->router->generate(
57 "ezpublish_rest_loadContentType{$urlTypeSuffix}FieldDefinition",
58 [
59 'contentTypeId' => $contentType->id,
60 'fieldDefinitionId' => $fieldDefinition->id,
61 ]
62 )
63 );
64 $generator->endAttribute('href');
65
66 $generator->startValueElement('id', $fieldDefinition->id);
67 $generator->endValueElement('id');
68
69 $generator->startValueElement('identifier', $fieldDefinition->identifier);
70 $generator->endValueElement('identifier');
71
72 $generator->startValueElement('fieldType', $fieldDefinition->fieldTypeIdentifier);
73 $generator->endValueElement('fieldType');
74
75 $generator->startValueElement('fieldGroup', $fieldDefinition->fieldGroup);
76 $generator->endValueElement('fieldGroup');
77
78 $generator->startValueElement('position', $fieldDefinition->position);
79 $generator->endValueElement('position');
80
81 $generator->startValueElement(
82 'isTranslatable',
83 $this->serializeBool($generator, $fieldDefinition->isTranslatable)
84 );
85 $generator->endValueElement('isTranslatable');
86
87 $generator->startValueElement(
88 'isRequired',
89 $this->serializeBool($generator, $fieldDefinition->isRequired)
90 );
91 $generator->endValueElement('isRequired');
92
93 $generator->startValueElement(
94 'isInfoCollector',
95 $this->serializeBool($generator, $fieldDefinition->isInfoCollector)
96 );
97 $generator->endValueElement('isInfoCollector');
98
99 $this->fieldTypeSerializer->serializeFieldDefaultValue(
100 $generator,
101 $fieldDefinition->fieldTypeIdentifier,
102 $fieldDefinition->defaultValue
103 );
104
105 $generator->startValueElement(
106 'isSearchable',
107 $this->serializeBool($generator, $fieldDefinition->isSearchable)
108 );
109 $generator->endValueElement('isSearchable');
110
111 $this->visitNamesList($generator, $fieldDefinition->getNames());
112
113 $descriptions = $fieldDefinition->getDescriptions();
114 if (is_array($descriptions)) {
115 $this->visitDescriptionsList($generator, $descriptions);
116 }
117
118 $this->fieldTypeSerializer->serializeFieldSettings(
119 $generator,
120 $fieldDefinition->fieldTypeIdentifier,
121 $fieldDefinition->getFieldSettings()
122 );
123
124 $this->fieldTypeSerializer->serializeValidatorConfiguration(
125 $generator,
126 $fieldDefinition->fieldTypeIdentifier,
127 $fieldDefinition->getValidatorConfiguration()
128 );
129
130 $generator->endObjectElement('FieldDefinition');
131 }
132 }
eZ\Publish\API\Repository\Values\ContentType\ContentType
Definition: API/Repository/Values/ContentType/ContentType.php:36
eZ\Publish\Core\REST\Common\Output\FieldTypeSerializer
Serializes FieldType related data for REST output.
Definition: FieldTypeSerializer.php:19
eZ\Publish\Core\REST\Common\Output\Generator
Output generator.
Definition: REST/Common/Output/Generator.php:13
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor\visitNamesList
visitNamesList(Generator $generator, array $names)
Visits the given list of $names.
Definition: ValueObjectVisitor.php:78
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor\serializeBool
serializeBool(Generator $generator, $boolValue)
Returns a string representation for the given $boolValue.
Definition: ValueObjectVisitor.php:67
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor\visitDescriptionsList
visitDescriptionsList(Generator $generator, array $descriptions)
Visits the given list of $descriptions.
Definition: ValueObjectVisitor.php:89
eZ\Publish\Core\REST\Common\Output\Visitor
Visits a value object into an HTTP Response.
Definition: Visitor.php:15
eZ\Publish\Core\REST\Common\Output\Visitor\setHeader
setHeader($name, $value)
Set HTTP response header.
Definition: Visitor.php:64
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestContentTypeBase
Base for RestContentType related value object visitors.
Definition: RestContentTypeBase.php:16
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestContentTypeBase\getUrlTypeSuffix
getUrlTypeSuffix($contentTypeStatus)
Returns a suffix for the URL type to generate on basis of the given $contentTypeStatus.
Definition: RestContentTypeBase.php:25
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestFieldDefinition
RestFieldDefinition value object visitor.
Definition: Output/ValueObjectVisitor/RestFieldDefinition.php:20
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestFieldDefinition\__construct
__construct(FieldTypeSerializer $fieldTypeSerializer)
Definition: Output/ValueObjectVisitor/RestFieldDefinition.php:27
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestFieldDefinition\$fieldTypeSerializer
$fieldTypeSerializer
Definition: Output/ValueObjectVisitor/RestFieldDefinition.php:22
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestFieldDefinition\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
Definition: Output/ValueObjectVisitor/RestFieldDefinition.php:39
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor
Definition: Output/ValueObjectVisitor/BadRequestException.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.