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

Output/ValueObjectVisitor/RestContentType.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\API\Repository\Values\ContentType\ContentType as APIContentType;
12 use eZ\Publish\Core\REST\Server\Values;
13
17 class RestContentType extends RestContentTypeBase
18 {
26 public function visit(Visitor $visitor, Generator $generator, $data)
27 {
28 $contentType = $data->contentType;
29
30 $urlTypeSuffix = $this->getUrlTypeSuffix($contentType->status);
31 $mediaType = $data->fieldDefinitions !== null ? 'ContentType' : 'ContentTypeInfo';
32
33 $generator->startObjectElement($mediaType);
34
35 $visitor->setHeader('Content-Type', $generator->getMediaType($mediaType));
36
37 if ($contentType->status === APIContentType::STATUS_DRAFT) {
38 $visitor->setHeader('Accept-Patch', $generator->getMediaType('ContentTypeUpdate'));
39 }
40
41 $generator->startAttribute(
42 'href',
43 $this->router->generate(
44 'ezpublish_rest_loadContentType' . $urlTypeSuffix,
45 [
46 'contentTypeId' => $contentType->id,
47 ]
48 )
49 );
50 $generator->endAttribute('href');
51
52 $generator->startValueElement('id', $contentType->id);
53 $generator->endValueElement('id');
54
55 $generator->startValueElement('status', $this->serializeStatus($contentType->status));
56 $generator->endValueElement('status');
57
58 $generator->startValueElement('identifier', $contentType->identifier);
59 $generator->endValueElement('identifier');
60
61 $this->visitNamesList($generator, $contentType->getNames());
62
63 $descriptions = $contentType->getDescriptions();
64 if (is_array($descriptions)) {
65 $this->visitDescriptionsList($generator, $descriptions);
66 }
67
68 $generator->startValueElement('creationDate', $contentType->creationDate->format('c'));
69 $generator->endValueElement('creationDate');
70
71 $generator->startValueElement('modificationDate', $contentType->modificationDate->format('c'));
72 $generator->endValueElement('modificationDate');
73
74 $generator->startObjectElement('Creator', 'User');
75 $generator->startAttribute(
76 'href',
77 $this->router->generate(
78 'ezpublish_rest_loadUser',
79 ['userId' => $contentType->creatorId]
80 )
81 );
82 $generator->endAttribute('href');
83 $generator->endObjectElement('Creator');
84
85 $generator->startObjectElement('Modifier', 'User');
86 $generator->startAttribute(
87 'href',
88 $this->router->generate(
89 'ezpublish_rest_loadUser',
90 ['userId' => $contentType->modifierId]
91 )
92 );
93 $generator->endAttribute('href');
94 $generator->endObjectElement('Modifier');
95
96 $generator->startObjectElement('Groups', 'ContentTypeGroupRefList');
97 $generator->startAttribute(
98 'href',
99 $this->router->generate(
100 'ezpublish_rest_loadGroupsOfContentType',
101 ['contentTypeId' => $contentType->id]
102 )
103 );
104 $generator->endAttribute('href');
105 $generator->endObjectElement('Groups');
106
107 $generator->startObjectElement('Draft', 'ContentType');
108 $generator->startAttribute(
109 'href',
110 $this->router->generate(
111 'ezpublish_rest_loadContentTypeDraft',
112 ['contentTypeId' => $contentType->id]
113 )
114 );
115 $generator->endAttribute('href');
116 $generator->endObjectElement('Draft');
117
118 $generator->startValueElement('remoteId', $contentType->remoteId);
119 $generator->endValueElement('remoteId');
120
121 $generator->startValueElement('urlAliasSchema', $contentType->urlAliasSchema);
122 $generator->endValueElement('urlAliasSchema');
123
124 $generator->startValueElement('nameSchema', $contentType->nameSchema);
125 $generator->endValueElement('nameSchema');
126
127 $generator->startValueElement(
128 'isContainer',
129 $this->serializeBool($generator, $contentType->isContainer)
130 );
131 $generator->endValueElement('isContainer');
132
133 $generator->startValueElement('mainLanguageCode', $contentType->mainLanguageCode);
134 $generator->endValueElement('mainLanguageCode');
135
136 $generator->startValueElement(
137 'defaultAlwaysAvailable',
138 $this->serializeBool($generator, $contentType->defaultAlwaysAvailable)
139 );
140 $generator->endValueElement('defaultAlwaysAvailable');
141
142 $generator->startValueElement('defaultSortField', $this->serializeSortField($contentType->defaultSortField));
143 $generator->endValueElement('defaultSortField');
144
145 $generator->startValueElement('defaultSortOrder', $this->serializeSortOrder($contentType->defaultSortOrder));
146 $generator->endValueElement('defaultSortOrder');
147
148 if ($data->fieldDefinitions !== null) {
149 $visitor->visitValueObject(
150 new Values\FieldDefinitionList(
151 $contentType,
152 $data->fieldDefinitions
153 )
154 );
155 }
156
157 $generator->endObjectElement($mediaType);
158 }
159 }
eZ\Publish\API\Repository\Values\ContentType\ContentType
Definition: API/Repository/Values/ContentType/ContentType.php:36
eZ\Publish\Core\REST\Common\Output\Generator
Output generator.
Definition: REST/Common/Output/Generator.php:13
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor\serializeSortField
serializeSortField($sortField)
Serializes the given $sortField to a string representation.
Definition: ValueObjectVisitor.php:149
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\serializeSortOrder
serializeSortOrder($sortOrder)
Serializes the given $sortOrder to a string representation.
Definition: ValueObjectVisitor.php:188
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\visitValueObject
visitValueObject($data)
Visit struct returned by controllers.
Definition: Visitor.php:131
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\FieldDefinitionList
FieldDefinitionList value object visitor.
Definition: Server/Output/ValueObjectVisitor/FieldDefinitionList.php:17
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\serializeStatus
serializeStatus($contentTypeStatus)
Serializes the given $contentTypeStatus to a string representation.
Definition: RestContentTypeBase.php:48
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\RestContentType
RestContentType value object visitor.
Definition: Output/ValueObjectVisitor/RestContentType.php:18
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\RestContentType\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
Definition: Output/ValueObjectVisitor/RestContentType.php:26
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor
Definition: Output/ValueObjectVisitor/BadRequestException.php:7
eZ\Publish\Core\REST\Server\Values
Definition: Core/REST/Server/Values/BookmarkList.php:9
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.