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

Core/FieldType/Media/Type.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Media;
8
9 use eZ\Publish\Core\FieldType\BinaryBase\Type as BaseType;
10 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentType;
11 use eZ\Publish\SPI\Persistence\Content\FieldValue;
12 use eZ\Publish\Core\FieldType\ValidationError;
13 use eZ\Publish\Core\FieldType\Value as BaseValue;
14 use eZ\Publish\SPI\fieldType\Value as SPIValue;
15
21 class Type extends BaseType
22 {
26 const TYPE_FLASH = 'flash';
27 const TYPE_QUICKTIME = 'quick_time';
28 const TYPE_REALPLAYER = 'real_player';
29 const TYPE_SILVERLIGHT = 'silverlight';
30 const TYPE_WINDOWSMEDIA = 'windows_media_player';
31 const TYPE_HTML5_VIDEO = 'html5_video';
32 const TYPE_HTML5_AUDIO = 'html5_audio';
33
37 private static $availableTypes = [
38 self::TYPE_FLASH,
39 self::TYPE_QUICKTIME,
40 self::TYPE_REALPLAYER,
41 self::TYPE_SILVERLIGHT,
42 self::TYPE_WINDOWSMEDIA,
43 self::TYPE_HTML5_VIDEO,
44 self::TYPE_HTML5_AUDIO,
45 ];
46
48 protected $settingsSchema = [
49 'mediaType' => [
50 'type' => 'choice',
51 'default' => self::TYPE_HTML5_VIDEO,
52 ],
53 ];
54
60 public function getFieldTypeIdentifier()
61 {
62 return 'ezmedia';
63 }
64
71 public function getEmptyValue()
72 {
73 return new Value();
74 }
75
83 public function validateFieldSettings($fieldSettings)
84 {
85 $validationErrors = [];
86
87 foreach ($fieldSettings as $name => $value) {
88 if (isset($this->settingsSchema[$name])) {
89 switch ($name) {
90 case 'mediaType':
91 if (!in_array($value, self::$availableTypes)) {
92 $validationErrors[] = new ValidationError(
93 "Setting '%setting%' is of unknown type",
94 null,
95 [
96 '%setting%' => $name,
97 ],
98 "[$name]"
99 );
100 }
101 break;
102 }
103 } else {
104 $validationErrors[] = new ValidationError(
105 "Setting '%setting%' is unknown",
106 null,
107 [
108 '%setting%' => $name,
109 ],
110 "[$name]"
111 );
112 }
113 }
114
115 return $validationErrors;
116 }
117
125 protected function createValue(array $inputValue)
126 {
127 $inputValue = $this->regenerateUri($inputValue);
128
129 return new Value($inputValue);
130 }
131
139 protected function checkValueStructure(BaseValue $value)
140 {
141 parent::checkValueStructure($value);
142
143 if (!is_bool($value->hasController)) {
144 throw new InvalidArgumentType(
145 '$value->hasController',
146 'bool',
147 $value->hasController
148 );
149 }
150 if (!is_bool($value->autoplay)) {
151 throw new InvalidArgumentType(
152 '$value->autoplay',
153 'bool',
154 $value->autoplay
155 );
156 }
157 if (!is_bool($value->loop)) {
158 throw new InvalidArgumentType(
159 '$value->loop',
160 'bool',
161 $value->loop
162 );
163 }
164
165 if (!is_int($value->height)) {
166 throw new InvalidArgumentType(
167 '$value->height',
168 'int',
169 $value->height
170 );
171 }
172 if (!is_int($value->width)) {
173 throw new InvalidArgumentType(
174 '$value->width',
175 'int',
176 $value->width
177 );
178 }
179 }
180
186 protected function completeValue(BaseValue $value)
187 {
188 parent::completeValue($value);
189
190 if (isset($value->hasController) && $value->hasController === null) {
191 $value->hasController = false;
192 }
193 if (isset($value->autoplay) && $value->autoplay === null) {
194 $value->autoplay = false;
195 }
196 if (isset($value->loop) && $value->loop === null) {
197 $value->loop = false;
198 }
199
200 if (isset($value->height) && $value->height === null) {
201 $value->height = 0;
202 }
203 if (isset($value->width) && $value->width === null) {
204 $value->width = 0;
205 }
206 }
207
215 public function toHash(SPIValue $value)
216 {
217 if ($this->isEmptyValue($value)) {
218 return null;
219 }
220
221 $hash = parent::toHash($value);
222
223 $hash['hasController'] = $value->hasController;
224 $hash['autoplay'] = $value->autoplay;
225 $hash['loop'] = $value->loop;
226 $hash['width'] = $value->width;
227 $hash['height'] = $value->height;
228
229 return $hash;
230 }
231
241 public function fromPersistenceValue(FieldValue $fieldValue)
242 {
243 if ($fieldValue->externalData === null) {
244 return $this->getEmptyValue();
245 }
246
247 $result = parent::fromPersistenceValue($fieldValue);
248
249 $result->hasController = (isset($fieldValue->externalData['hasController'])
250 ? $fieldValue->externalData['hasController']
251 : false);
252 $result->autoplay = (isset($fieldValue->externalData['autoplay'])
253 ? $fieldValue->externalData['autoplay']
254 : false);
255 $result->loop = (isset($fieldValue->externalData['loop'])
256 ? $fieldValue->externalData['loop']
257 : false);
258 $result->height = (isset($fieldValue->externalData['height'])
259 ? $fieldValue->externalData['height']
260 : 0);
261 $result->width = (isset($fieldValue->externalData['width'])
262 ? $fieldValue->externalData['width']
263 : 0);
264
265 return $result;
266 }
267
273 public function isSearchable()
274 {
275 return false;
276 }
277 }
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\BinaryBase\Type
Base FileType class for Binary field types (i.e.
Definition: Core/FieldType/BinaryBase/Type.php:23
eZ\Publish\Core\FieldType\BinaryBase\Type\regenerateUri
regenerateUri(array $inputValue)
Definition: Core/FieldType/BinaryBase/Type.php:60
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\Media\Type
The TextLine field type.
Definition: Core/FieldType/Media/Type.php:22
eZ\Publish\Core\FieldType\Media\Type\TYPE_SILVERLIGHT
const TYPE_SILVERLIGHT
Definition: Core/FieldType/Media/Type.php:29
eZ\Publish\Core\FieldType\Media\Type\isSearchable
isSearchable()
Returns whether the field type is searchable.
Definition: Core/FieldType/Media/Type.php:273
eZ\Publish\Core\FieldType\Media\Type\TYPE_HTML5_VIDEO
const TYPE_HTML5_VIDEO
Definition: Core/FieldType/Media/Type.php:31
eZ\Publish\Core\FieldType\Media\Type\createValue
createValue(array $inputValue)
Creates a specific value of the derived class from $inputValue.
Definition: Core/FieldType/Media/Type.php:125
eZ\Publish\Core\FieldType\Media\Type\TYPE_REALPLAYER
const TYPE_REALPLAYER
Definition: Core/FieldType/Media/Type.php:28
eZ\Publish\Core\FieldType\Media\Type\TYPE_FLASH
const TYPE_FLASH
List of possible media type settings.
Definition: Core/FieldType/Media/Type.php:26
eZ\Publish\Core\FieldType\Media\Type\$availableTypes
static $availableTypes
Type constants for validation.
Definition: Core/FieldType/Media/Type.php:37
eZ\Publish\Core\FieldType\Media\Type\TYPE_QUICKTIME
const TYPE_QUICKTIME
Definition: Core/FieldType/Media/Type.php:27
eZ\Publish\Core\FieldType\Media\Type\$settingsSchema
$settingsSchema
Definition: Core/FieldType/Media/Type.php:48
eZ\Publish\Core\FieldType\Media\Type\fromPersistenceValue
fromPersistenceValue(FieldValue $fieldValue)
Converts a persistence $fieldValue to a Value.
Definition: Core/FieldType/Media/Type.php:241
eZ\Publish\Core\FieldType\Media\Type\toHash
toHash(SPIValue $value)
Converts a $Value to a hash.
Definition: Core/FieldType/Media/Type.php:215
eZ\Publish\Core\FieldType\Media\Type\checkValueStructure
checkValueStructure(BaseValue $value)
Throws an exception if value structure is not of expected format.
Definition: Core/FieldType/Media/Type.php:139
eZ\Publish\Core\FieldType\Media\Type\validateFieldSettings
validateFieldSettings($fieldSettings)
Validates the fieldSettings of a FieldDefinitionCreateStruct or FieldDefinitionUpdateStruct.
Definition: Core/FieldType/Media/Type.php:83
eZ\Publish\Core\FieldType\Media\Type\TYPE_HTML5_AUDIO
const TYPE_HTML5_AUDIO
Definition: Core/FieldType/Media/Type.php:32
eZ\Publish\Core\FieldType\Media\Type\completeValue
completeValue(BaseValue $value)
Attempts to complete the data in $value.
Definition: Core/FieldType/Media/Type.php:186
eZ\Publish\Core\FieldType\Media\Type\getFieldTypeIdentifier
getFieldTypeIdentifier()
Returns the field type identifier for this field type.
Definition: Core/FieldType/Media/Type.php:60
eZ\Publish\Core\FieldType\Media\Type\getEmptyValue
getEmptyValue()
Returns the fallback default value of field type when no such default value is provided in the field ...
Definition: Core/FieldType/Media/Type.php:71
eZ\Publish\Core\FieldType\Media\Type\TYPE_WINDOWSMEDIA
const TYPE_WINDOWSMEDIA
Definition: Core/FieldType/Media/Type.php:30
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\Persistence\Content\FieldValue
Definition: FieldValue.php:12
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.