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

Relation/NameableField.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Relation;
8
9 use eZ\Publish\API\Repository\Exceptions\NotFoundException;
10 use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
11 use eZ\Publish\SPI\FieldType\Nameable;
12 use eZ\Publish\SPI\FieldType\Value as SPIValue;
13 use eZ\Publish\SPI\Persistence\Content\Handler as SPIContentHandler;
14
18 class NameableField implements Nameable
19 {
21 private $handler;
22
26 public function __construct(SPIContentHandler $handler)
27 {
28 $this->handler = $handler;
29 }
30
38 public function getFieldName(SPIValue $value, FieldDefinition $fieldDefinition, $languageCode)
39 {
40 if (empty($value->destinationContentId)) {
41 return '';
42 }
43
44 try {
45 $contentInfo = $this->handler->loadContentInfo($value->destinationContentId);
46 $versionInfo = $this->handler->loadVersionInfo($value->destinationContentId, $contentInfo->currentVersionNo);
47 } catch (NotFoundException $e) {
48 return '';
49 }
50
51 if (isset($versionInfo->names[$languageCode])) {
52 return $versionInfo->names[$languageCode];
53 }
54
55 return $versionInfo->names[$contentInfo->mainLanguageCode];
56 }
57 }
eZ\Publish\API\Repository\Exceptions\NotFoundException
This Exception is thrown if an object referenced by an id or identifier could not be found in the rep...
Definition: API/Repository/Exceptions/NotFoundException.php:16
eZ\Publish\API\Repository\Values\ContentType\FieldDefinition
Definition: API/Repository/Values/ContentType/FieldDefinition.php:31
eZ\Publish\Core\FieldType\Relation\NameableField
Class NameableField for Relation FieldType.
Definition: Relation/NameableField.php:19
eZ\Publish\Core\FieldType\Relation\NameableField\__construct
__construct(SPIContentHandler $handler)
Definition: Relation/NameableField.php:26
eZ\Publish\Core\FieldType\Relation\NameableField\getFieldName
getFieldName(SPIValue $value, FieldDefinition $fieldDefinition, $languageCode)
Definition: Relation/NameableField.php:38
eZ\Publish\Core\FieldType\Relation\NameableField\$handler
$handler
Definition: Relation/NameableField.php:21
eZ\Publish\SPI\FieldType\Nameable
The field type interface which all field types have to implement to be able to generate content name ...
Definition: Nameable.php:36
eZ\Publish\SPI\FieldType\Value
Interface for field value classes.
Definition: SPI/FieldType/Value.php:13
eZ\Publish\SPI\Persistence\Content\Handler
The Content Handler interface defines content operations on the storage engine.
Definition: SPI/Persistence/Content/Handler.php:20
eZ\Publish\Core\FieldType\Relation
Definition: Relation/NameableField.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.