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

Client/Output/ValueObjectVisitor/RestContentCreateStruct.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Client\Output\ValueObjectVisitor;
8
9 use eZ\Publish\API\Repository\Values\Content\Field;
10 use eZ\Publish\API\Repository\Values\ContentType\ContentType;
11 use eZ\Publish\Core\REST\Common\Output\FieldTypeSerializer;
12 use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
13 use eZ\Publish\Core\REST\Common\Output\Generator;
14 use eZ\Publish\Core\REST\Common\Output\Visitor;
15
19 class RestContentCreateStruct extends ValueObjectVisitor
20 {
21 public function __construct(FieldTypeSerializer $fieldTypeSerializer)
22 {
23 $this->fieldTypeSerializer = $fieldTypeSerializer;
24 }
25
31 public function visit(Visitor $visitor, Generator $generator, $restContentCreateStruct)
32 {
33 $contentCreateStruct = $restContentCreateStruct->contentCreateStruct;
34
35 $generator->startObjectElement('ContentCreate');
36 $visitor->setHeader('Content-Type', $generator->getMediaType('TypeCreate'));
37
38 $generator->startValueElement('mainLanguageCode', $contentCreateStruct->mainLanguageCode);
39 $generator->endValueElement('mainLanguageCode');
40
41 $generator->startValueElement('alwaysAvailable', $contentCreateStruct->alwaysAvailable ? 'true' : 'false');
42 $generator->endValueElement('alwaysAvailable');
43
44 $generator->startValueElement('remoteId', (int)$contentCreateStruct->remoteId);
45 $generator->endValueElement('remoteId');
46
47 if ($contentCreateStruct->modificationDate !== null) {
48 $generator->startValueElement('modificationDate', $contentCreateStruct->modificationDate->format('c'));
49 $generator->endValueElement('modificationDate');
50 }
51
52 if ($contentCreateStruct->ownerId !== null) {
53 $generator->startObjectElement('User');
54 $generator->startAttribute('href', $contentCreateStruct->ownerId);
55 $generator->endAttribute('href');
56 $generator->endObjectElement('User');
57 }
58
59 $generator->startObjectElement('ContentType');
60 $generator->startAttribute(
61 'href',
62 $this->router->generate(
63 'ezpublish_rest_loadContentType',
64 array('contentTypeId' => $contentCreateStruct->contentType->id)
65 )
66 );
67 $generator->endAttribute('href');
68 $generator->endObjectElement('ContentType');
69
70 if (!empty($contentCreateStruct->fields)) {
71 $generator->startHashElement('fields');
72 $generator->startList('field');
73
74 foreach ($contentCreateStruct->fields as $field) {
75 $this->visitField($generator, $contentCreateStruct->contentType, $field);
76 }
77 $generator->endList('field');
78 $generator->endHashElement('fields');
79 }
80
81 $visitor->visitValueObject($restContentCreateStruct->locationCreateStruct);
82
83 $generator->endObjectElement('ContentCreate');
84 }
85
93 public function visitField(Generator $generator, ContentType $contentType, Field $field)
94 {
95 $generator->startHashElement('field');
96
97 $generator->startValueElement('fieldDefinitionIdentifier', $field->fieldDefIdentifier);
98 $generator->endValueElement('fieldDefinitionIdentifier');
99
100 $generator->startValueElement('languageCode', $field->languageCode);
101 $generator->endValueElement('languageCode');
102
103 $this->fieldTypeSerializer->serializeFieldValue(
104 $generator,
105 $contentType,
106 $field
107 );
108
109 $generator->endHashElement('field');
110 }
111 }
eZ\Publish\API\Repository\Values\ContentType\ContentType
Definition: API/Repository/Values/ContentType/ContentType.php:36
eZ\Publish\API\Repository\Values\Content\Field
Definition: API/Repository/Values/Content/Field.php:21
eZ\Publish\Core\REST\Client\Output\ValueObjectVisitor\RestContentCreateStruct
ContentCreateStruct value object visitor.
Definition: Client/Output/ValueObjectVisitor/RestContentCreateStruct.php:20
eZ\Publish\Core\REST\Client\Output\ValueObjectVisitor\RestContentCreateStruct\visitField
visitField(Generator $generator, ContentType $contentType, Field $field)
Visits a single content field and generates its content.
Definition: Client/Output/ValueObjectVisitor/RestContentCreateStruct.php:93
eZ\Publish\Core\REST\Client\Output\ValueObjectVisitor\RestContentCreateStruct\visit
visit(Visitor $visitor, Generator $generator, $restContentCreateStruct)
Definition: Client/Output/ValueObjectVisitor/RestContentCreateStruct.php:31
eZ\Publish\Core\REST\Client\Output\ValueObjectVisitor\RestContentCreateStruct\__construct
__construct(FieldTypeSerializer $fieldTypeSerializer)
Definition: Client/Output/ValueObjectVisitor/RestContentCreateStruct.php:21
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
Basic ValueObjectVisitor.
Definition: ValueObjectVisitor.php:18
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\Client\Output\ValueObjectVisitor
Definition: Client/Output/ValueObjectVisitor/ContentObjectStates.php:7
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
Definition: Common/Output/ValueObjectVisitor/ContentObjectStates.php:7
eZ\Publish\SPI\Persistence\Content\Type
Definition: SPI/Persistence/Content/Type/CreateStruct.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.