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

Core/FieldType/TextBlock/Type.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\TextBlock;
8
9 use eZ\Publish\Core\FieldType\FieldType;
10 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
11 use eZ\Publish\Core\FieldType\ValidationError;
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 {
22 protected $settingsSchema = [
23 'textRows' => [
24 'type' => 'int',
25 'default' => 10,
26 ],
27 ];
28
29 protected $validatorConfigurationSchema = [];
30
36 public function getFieldTypeIdentifier()
37 {
38 return 'eztext';
39 }
40
51 public function getName(SPIValue $value)
52 {
53 return (string)$value->text;
54 }
55
62 public function getEmptyValue()
63 {
64 return new Value();
65 }
66
74 public function isEmptyValue(SPIValue $value)
75 {
76 return $value->text === null || trim($value->text) === '';
77 }
78
86 protected function createValueFromInput($inputValue)
87 {
88 if (is_string($inputValue)) {
89 $inputValue = new Value($inputValue);
90 }
91
92 return $inputValue;
93 }
94
102 protected function checkValueStructure(BaseValue $value)
103 {
104 if (!is_string($value->text)) {
105 throw new InvalidArgumentType(
106 '$value->text',
107 'string',
108 $value->text
109 );
110 }
111 }
112
120 protected function getSortInfo(BaseValue $value)
121 {
122 return $this->transformationProcessor->transformByGroup(
123 mb_substr(strtok(trim($value->text), "\r\n"), 0, 255),
124 'lowercase'
125 );
126 }
127
135 public function fromHash($hash)
136 {
137 if ($hash === null) {
138 return $this->getEmptyValue();
139 }
140
141 return new Value($hash);
142 }
143
151 public function toHash(SPIValue $value)
152 {
153 if ($this->isEmptyValue($value)) {
154 return null;
155 }
156
157 return $value->text;
158 }
159
165 public function isSearchable()
166 {
167 return true;
168 }
169
177 public function validateFieldSettings($fieldSettings)
178 {
179 $validationErrors = [];
180
181 foreach ($fieldSettings as $name => $value) {
182 if (isset($this->settingsSchema[$name])) {
183 switch ($name) {
184 case 'textRows':
185 if (!is_int($value)) {
186 $validationErrors[] = new ValidationError(
187 "Setting '%setting%' value must be of integer type",
188 null,
189 [
190 '%setting%' => $name,
191 ],
192 "[$name]"
193 );
194 }
195 break;
196 }
197 } else {
198 $validationErrors[] = new ValidationError(
199 "Setting '%setting%' is unknown",
200 null,
201 [
202 '%setting%' => $name,
203 ],
204 "[$name]"
205 );
206 }
207 }
208
209 return $validationErrors;
210 }
211 }
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\TextBlock\Type
The TextBlock field type.
Definition: Core/FieldType/TextBlock/Type.php:21
eZ\Publish\Core\FieldType\TextBlock\Type\getSortInfo
getSortInfo(BaseValue $value)
Returns information for FieldValue->$sortKey relevant to the field type.
Definition: Core/FieldType/TextBlock/Type.php:120
eZ\Publish\Core\FieldType\TextBlock\Type\getEmptyValue
getEmptyValue()
Returns the fallback default value of field type when no such default value is provided in the field ...
Definition: Core/FieldType/TextBlock/Type.php:62
eZ\Publish\Core\FieldType\TextBlock\Type\$settingsSchema
$settingsSchema
Definition: Core/FieldType/TextBlock/Type.php:22
eZ\Publish\Core\FieldType\TextBlock\Type\$validatorConfigurationSchema
$validatorConfigurationSchema
Definition: Core/FieldType/TextBlock/Type.php:29
eZ\Publish\Core\FieldType\TextBlock\Type\isSearchable
isSearchable()
Returns whether the field type is searchable.
Definition: Core/FieldType/TextBlock/Type.php:165
eZ\Publish\Core\FieldType\TextBlock\Type\isEmptyValue
isEmptyValue(SPIValue $value)
Returns if the given $value is considered empty by the field type.
Definition: Core/FieldType/TextBlock/Type.php:74
eZ\Publish\Core\FieldType\TextBlock\Type\checkValueStructure
checkValueStructure(BaseValue $value)
Throws an exception if value structure is not of expected format.
Definition: Core/FieldType/TextBlock/Type.php:102
eZ\Publish\Core\FieldType\TextBlock\Type\getName
getName(SPIValue $value)
Returns the name of the given field value.
Definition: Core/FieldType/TextBlock/Type.php:51
eZ\Publish\Core\FieldType\TextBlock\Type\fromHash
fromHash($hash)
Converts an $hash to the Value defined by the field type.
Definition: Core/FieldType/TextBlock/Type.php:135
eZ\Publish\Core\FieldType\TextBlock\Type\getFieldTypeIdentifier
getFieldTypeIdentifier()
Returns the field type identifier for this field type.
Definition: Core/FieldType/TextBlock/Type.php:36
eZ\Publish\Core\FieldType\TextBlock\Type\toHash
toHash(SPIValue $value)
Converts a $Value to a hash.
Definition: Core/FieldType/TextBlock/Type.php:151
eZ\Publish\Core\FieldType\TextBlock\Type\createValueFromInput
createValueFromInput($inputValue)
Inspects given $inputValue and potentially converts it into a dedicated value object.
Definition: Core/FieldType/TextBlock/Type.php:86
eZ\Publish\Core\FieldType\TextBlock\Type\validateFieldSettings
validateFieldSettings($fieldSettings)
Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.
Definition: Core/FieldType/TextBlock/Type.php:177
eZ\Publish\Core\FieldType\ValidationError
Class for validation errors.
Definition: Core/FieldType/ValidationError.php:17
eZ\Publish\Core\FieldType\Value
Abstract class for all field value classes.
Definition: Core/FieldType/Value.php:17
eZ\Publish\SPI\FieldType\Value
Interface for field value classes.
Definition: SPI/FieldType/Value.php:13
eZ\Publish\Core\FieldType\TextBlock
Definition: TextBlock/SearchField.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.