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

Output/ValueObjectVisitor/VersionTranslationInfo.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\ValueObjectVisitor;
10 use eZ\Publish\Core\REST\Common\Output\Generator;
11 use eZ\Publish\Core\REST\Common\Output\Visitor;
12 use eZ\Publish\Core\REST\Server\Values\VersionTranslationInfo as VersionTranslationInfoValue;
13
17 class VersionTranslationInfo extends ValueObjectVisitor
18 {
26 public function visit(Visitor $visitor, Generator $generator, $data)
27 {
28 $versionInfo = $data->getVersionInfo();
29 if (empty($versionInfo->languageCodes)) {
30 return;
31 }
32
33 $generator->startObjectElement('VersionTranslationInfo');
34 $this->visitVersionTranslationInfoAttributes($visitor, $generator, $data);
35 $generator->endObjectElement('VersionTranslationInfo');
36 }
37
38 protected function visitVersionTranslationInfoAttributes(Visitor $visitor, Generator $generator, VersionTranslationInfoValue $versionTranslationInfo)
39 {
40 $versionInfo = $versionTranslationInfo->getVersionInfo();
41
42 // single language-independent conditions for deleting Translation
43 $canDelete = count($versionInfo->languageCodes) >= 2 && $versionInfo->isDraft();
44
45 $generator->startList('Language');
46 foreach ($versionInfo->languageCodes as $languageCode) {
47 $generator->startHashElement('Language');
48
49 $generator->startValueElement('languageCode', $languageCode);
50 $generator->endValueElement('languageCode');
51
52 // check conditions for deleting Translation
53 if ($canDelete && $languageCode !== $versionInfo->contentInfo->mainLanguageCode) {
54 $generator->startHashElement('DeleteTranslation');
55 $path = $this->router->generate(
56 'ezpublish_rest_deleteTranslationFromDraft',
57 [
58 'contentId' => $versionInfo->contentInfo->id,
59 'versionNumber' => $versionInfo->versionNo,
60 'languageCode' => $languageCode,
61 ]
62 );
63 $generator->startAttribute('href', $path);
64 $generator->endAttribute('href');
65 $generator->endHashElement('DeleteTranslation');
66 }
67
68 $generator->endHashElement('Language');
69 }
70 $generator->endList('Language');
71 }
72 }
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\Server\Output\ValueObjectVisitor\VersionTranslationInfo
Version value object visitor.
Definition: Output/ValueObjectVisitor/VersionTranslationInfo.php:18
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\VersionTranslationInfo\visit
visit(Visitor $visitor, Generator $generator, $data)
Visit struct returned by controllers.
Definition: Output/ValueObjectVisitor/VersionTranslationInfo.php:26
eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor\VersionTranslationInfo\visitVersionTranslationInfoAttributes
visitVersionTranslationInfoAttributes(Visitor $visitor, Generator $generator, VersionTranslationInfoValue $versionTranslationInfo)
Definition: Output/ValueObjectVisitor/VersionTranslationInfo.php:38
eZ\Publish\Core\REST\Server\Values\VersionTranslationInfo
Version Translations information view model.
Definition: Values/VersionTranslationInfo.php:16
eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor
Definition: Common/Output/ValueObjectVisitor/ContentObjectStates.php:7
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+.