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

Core/FieldType/Url/Type.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Url;
8
9 use eZ\Publish\Core\FieldType\FieldType;
10 use eZ\Publish\SPI\Persistence\Content\FieldValue;
11 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
12 use eZ\Publish\SPI\FieldType\Value as SPIValue;
13 use eZ\Publish\Core\FieldType\Value as BaseValue;
14
20 class Type extends FieldType
21 {
27 public function getFieldTypeIdentifier()
28 {
29 return 'ezurl';
30 }
31
42 public function getName(SPIValue $value)
43 {
44 return (string)$value->text;
45 }
46
53 public function getEmptyValue()
54 {
55 return new Value();
56 }
57
65 protected function createValueFromInput($inputValue)
66 {
67 if (is_string($inputValue)) {
68 $inputValue = new Value($inputValue);
69 }
70
71 return $inputValue;
72 }
73
81 protected function checkValueStructure(BaseValue $value)
82 {
83 if (null !== $value->link && !is_string($value->link)) {
84 throw new InvalidArgumentType(
85 '$value->link',
86 'string',
87 $value->link
88 );
89 }
90
91 if (null !== $value->text && !is_string($value->text)) {
92 throw new InvalidArgumentType(
93 '$value->text',
94 'string',
95 $value->text
96 );
97 }
98 }
99
103 protected function getSortInfo(BaseValue $value)
104 {
105 return false;
106 }
107
115 public function fromHash($hash)
116 {
117 if ($hash === null) {
118 return $this->getEmptyValue();
119 }
120
121 if (isset($hash['text'])) {
122 return new Value($hash['link'], $hash['text']);
123 }
124
125 return new Value($hash['link']);
126 }
127
135 public function toHash(SPIValue $value)
136 {
137 if ($this->isEmptyValue($value)) {
138 return null;
139 }
140
141 return ['link' => $value->link, 'text' => $value->text];
142 }
143
166 public function toPersistenceValue(SPIValue $value)
167 {
168 if ($value === null) {
169 return new FieldValue(
170 [
171 'data' => [],
172 'externalData' => null,
173 'sortKey' => null,
174 ]
175 );
176 }
177
178 return new FieldValue(
179 [
180 'data' => [
181 'urlId' => null,
182 'text' => $value->text,
183 ],
184 'externalData' => $value->link,
185 'sortKey' => $this->getSortInfo($value),
186 ]
187 );
188 }
189
199 public function fromPersistenceValue(FieldValue $fieldValue)
200 {
201 if ($fieldValue->externalData === null) {
202 return $this->getEmptyValue();
203 }
204
205 return new Value(
206 $fieldValue->externalData,
207 $fieldValue->data['text']
208 );
209 }
210 }
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Value
Struct that stores extra value information for a Criterion object.
Definition: API/Repository/Values/Content/Query/Criterion/Value.php:13
eZ\Publish\Core\Base\Exceptions\InvalidArgumentType
Invalid Argument Type Exception implementation.
Definition: InvalidArgumentType.php:17
eZ\Publish\Core\FieldType\FieldType
Base class for field types, the most basic storage unit of data inside eZ Publish.
Definition: Core/FieldType/FieldType.php:35
eZ\Publish\Core\FieldType\FieldType\isEmptyValue
isEmptyValue(SPIValue $value)
Returns if the given $value is considered empty by the field type.
Definition: Core/FieldType/FieldType.php:350
eZ\Publish\Core\FieldType\Url\Type
The Url field type.
Definition: Core/FieldType/Url/Type.php:21
eZ\Publish\Core\FieldType\Url\Type\toPersistenceValue
toPersistenceValue(SPIValue $value)
Converts a $value to a persistence value.
Definition: Core/FieldType/Url/Type.php:166
eZ\Publish\Core\FieldType\Url\Type\fromPersistenceValue
fromPersistenceValue(FieldValue $fieldValue)
Converts a persistence $fieldValue to a Value.
Definition: Core/FieldType/Url/Type.php:199
eZ\Publish\Core\FieldType\Url\Type\toHash
toHash(SPIValue $value)
Converts a $Value to a hash.
Definition: Core/FieldType/Url/Type.php:135
eZ\Publish\Core\FieldType\Url\Type\createValueFromInput
createValueFromInput($inputValue)
Inspects given $inputValue and potentially converts it into a dedicated value object.
Definition: Core/FieldType/Url/Type.php:65
eZ\Publish\Core\FieldType\Url\Type\getSortInfo
getSortInfo(BaseValue $value)
{}
Definition: Core/FieldType/Url/Type.php:103
eZ\Publish\Core\FieldType\Url\Type\checkValueStructure
checkValueStructure(BaseValue $value)
Throws an exception if value structure is not of expected format.
Definition: Core/FieldType/Url/Type.php:81
eZ\Publish\Core\FieldType\Url\Type\getEmptyValue
getEmptyValue()
Returns the fallback default value of field type when no such default value is provided in the field ...
Definition: Core/FieldType/Url/Type.php:53
eZ\Publish\Core\FieldType\Url\Type\fromHash
fromHash($hash)
Converts an $hash to the Value defined by the field type.
Definition: Core/FieldType/Url/Type.php:115
eZ\Publish\Core\FieldType\Url\Type\getFieldTypeIdentifier
getFieldTypeIdentifier()
Returns the field type identifier for this field type.
Definition: Core/FieldType/Url/Type.php:27
eZ\Publish\Core\FieldType\Url\Type\getName
getName(SPIValue $value)
Returns the name of the given field value.
Definition: Core/FieldType/Url/Type.php:42
eZ\Publish\Core\FieldType\Value
Abstract class for all field value classes.
Definition: Core/FieldType/Value.php:17
eZ\Publish\SPI\Persistence\Content\FieldValue
Definition: FieldValue.php:12
eZ\Publish\SPI\FieldType\Value
Interface for field value classes.
Definition: SPI/FieldType/Value.php:13
eZ\Publish\Core\FieldType\Url
Definition: Url/SearchField.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.