Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Field/FieldItemInterface.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Field; | |
4 | |
5 use Drupal\Core\Form\FormStateInterface; | |
6 use Drupal\Core\TypedData\ComplexDataInterface; | |
7 | |
8 /** | |
9 * Interface for entity field items. | |
10 * | |
11 * Entity field items are typed data objects containing the field values, i.e. | |
12 * implementing the ComplexDataInterface. | |
13 * | |
14 * When implementing this interface which extends Traversable, make sure to list | |
15 * IteratorAggregate or Iterator before this interface in the implements clause. | |
16 * | |
17 * @see \Drupal\Core\Field\FieldItemListInterface | |
18 * @see \Drupal\Core\Field\FieldItemBase | |
19 * @ingroup field_types | |
20 */ | |
21 interface FieldItemInterface extends ComplexDataInterface { | |
22 | |
23 /** | |
24 * Defines field item properties. | |
25 * | |
26 * Properties that are required to constitute a valid, non-empty item should | |
27 * be denoted with \Drupal\Core\TypedData\DataDefinition::setRequired(). | |
28 * | |
29 * @return \Drupal\Core\TypedData\DataDefinitionInterface[] | |
30 * An array of property definitions of contained properties, keyed by | |
31 * property name. | |
32 * | |
33 * @see \Drupal\Core\Field\BaseFieldDefinition | |
34 */ | |
35 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition); | |
36 | |
37 /** | |
38 * Returns the name of the main property, if any. | |
39 * | |
40 * Some field items consist mainly of one main property, e.g. the value of a | |
41 * text field or the @code target_id @endcode of an entity reference. If the | |
42 * field item has no main property, the method returns NULL. | |
43 * | |
44 * @return string|null | |
45 * The name of the value property, or NULL if there is none. | |
46 * | |
47 * @see \Drupal\Core\Field\BaseFieldDefinition | |
48 */ | |
49 public static function mainPropertyName(); | |
50 | |
51 /** | |
52 * Returns the schema for the field. | |
53 * | |
54 * This method is static because the field schema information is needed on | |
55 * creation of the field. FieldItemInterface objects instantiated at that | |
56 * time are not reliable as field settings might be missing. | |
57 * | |
58 * Computed fields having no schema should return an empty array. | |
59 * | |
60 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $field_definition | |
61 * The field definition. | |
62 * | |
63 * @return array | |
64 * An empty array if there is no schema, or an associative array with the | |
65 * following key/value pairs: | |
66 * - columns: An array of Schema API column specifications, keyed by column | |
67 * name. The columns need to be a subset of the properties defined in | |
68 * propertyDefinitions(). The 'not null' property is ignored if present, | |
69 * as it is determined automatically by the storage controller depending | |
70 * on the table layout and the property definitions. It is recommended to | |
71 * avoid having the column definitions depend on field settings when | |
72 * possible. No assumptions should be made on how storage engines | |
73 * internally use the original column name to structure their storage. | |
74 * - unique keys: (optional) An array of Schema API unique key definitions. | |
75 * Only columns that appear in the 'columns' array are allowed. | |
76 * - indexes: (optional) An array of Schema API index definitions. Only | |
77 * columns that appear in the 'columns' array are allowed. Those indexes | |
78 * will be used as default indexes. Field definitions can specify | |
79 * additional indexes or, at their own risk, modify the default indexes | |
80 * specified by the field-type module. Some storage engines might not | |
81 * support indexes. | |
82 * - foreign keys: (optional) An array of Schema API foreign key | |
83 * definitions. Note, however, that the field data is not necessarily | |
84 * stored in SQL. Also, the possible usage is limited, as you cannot | |
85 * specify another field as related, only existing SQL tables, | |
86 * such as {taxonomy_term_data}. | |
87 */ | |
88 public static function schema(FieldStorageDefinitionInterface $field_definition); | |
89 | |
90 /** | |
91 * Gets the entity that field belongs to. | |
92 * | |
93 * @return \Drupal\Core\Entity\FieldableEntityInterface | |
94 * The entity object. | |
95 */ | |
96 public function getEntity(); | |
97 | |
98 /** | |
99 * Gets the langcode of the field values held in the object. | |
100 * | |
101 * @return string | |
102 * The langcode. | |
103 */ | |
104 public function getLangcode(); | |
105 | |
106 /** | |
107 * Gets the field definition. | |
108 * | |
109 * @return \Drupal\Core\Field\FieldDefinitionInterface | |
110 * The field definition. | |
111 */ | |
112 public function getFieldDefinition(); | |
113 | |
114 /** | |
115 * Magic method: Gets a property value. | |
116 * | |
117 * @param string $property_name | |
118 * The name of the property to get; e.g., 'title' or 'name'. | |
119 * | |
120 * @return mixed | |
121 * The property value. | |
122 * | |
123 * @throws \InvalidArgumentException | |
124 * If a not existing property is accessed. | |
125 */ | |
126 public function __get($property_name); | |
127 | |
128 /** | |
129 * Magic method: Sets a property value. | |
130 * | |
131 * @param string $property_name | |
132 * The name of the property to set; e.g., 'title' or 'name'. | |
133 * @param mixed $value | |
134 * The value to set, or NULL to unset the property. Optionally, a typed | |
135 * data object implementing Drupal\Core\TypedData\TypedDataInterface may be | |
136 * passed instead of a plain value. | |
137 * | |
138 * @throws \InvalidArgumentException | |
139 * If a not existing property is set. | |
140 */ | |
141 public function __set($property_name, $value); | |
142 | |
143 /** | |
144 * Magic method: Determines whether a property is set. | |
145 * | |
146 * @param string $property_name | |
147 * The name of the property to get; e.g., 'title' or 'name'. | |
148 * | |
149 * @return bool | |
150 * Returns TRUE if the property exists and is set, FALSE otherwise. | |
151 */ | |
152 public function __isset($property_name); | |
153 | |
154 /** | |
155 * Magic method: Unsets a property. | |
156 * | |
157 * @param string $property_name | |
158 * The name of the property to get; e.g., 'title' or 'name'. | |
159 */ | |
160 public function __unset($property_name); | |
161 | |
162 /** | |
163 * Returns a renderable array for a single field item. | |
164 * | |
165 * @param array $display_options | |
166 * Can be either the name of a view mode, or an array of display settings. | |
167 * See EntityViewBuilderInterface::viewField() for more information. | |
168 * | |
169 * @return array | |
170 * A renderable array for the field item. | |
171 * | |
172 * @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewField() | |
173 * @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewFieldItem() | |
174 * @see \Drupal\Core\Field\FieldItemListInterface::view() | |
175 */ | |
176 public function view($display_options = []); | |
177 | |
178 /** | |
179 * Defines custom presave behavior for field values. | |
180 * | |
181 * This method is called during the process of saving an entity, just before | |
182 * values are written into storage. When storing a new entity, its identifier | |
183 * will not be available yet. This should be used to massage item property | |
184 * values or perform any other operation that needs to happen before values | |
185 * are stored. For instance this is the proper phase to auto-create a new | |
186 * entity for an entity reference field item, because this way it will be | |
187 * possible to store the referenced entity identifier. | |
188 */ | |
189 public function preSave(); | |
190 | |
191 /** | |
192 * Defines custom post-save behavior for field values. | |
193 * | |
194 * This method is called during the process of saving an entity, just after | |
195 * values are written into storage. This is useful mostly when the business | |
196 * logic to be implemented always requires the entity identifier, even when | |
197 * storing a new entity. For instance, when implementing circular entity | |
198 * references, the referenced entity will be created on pre-save with a dummy | |
199 * value for the referring entity identifier, which will be updated with the | |
200 * actual one on post-save. | |
201 * | |
202 * In the rare cases where item properties depend on the entity identifier, | |
203 * massaging logic will have to be implemented on post-save and returning TRUE | |
204 * will allow them to be rewritten to the storage with the updated values. | |
205 * | |
206 * @param bool $update | |
207 * Specifies whether the entity is being updated or created. | |
208 * | |
209 * @return bool | |
210 * Whether field items should be rewritten to the storage as a consequence | |
211 * of the logic implemented by the custom behavior. | |
212 */ | |
213 public function postSave($update); | |
214 | |
215 /** | |
216 * Defines custom delete behavior for field values. | |
217 * | |
218 * This method is called during the process of deleting an entity, just before | |
219 * values are deleted from storage. | |
220 */ | |
221 public function delete(); | |
222 | |
223 /** | |
224 * Defines custom revision delete behavior for field values. | |
225 * | |
226 * This method is called from during the process of deleting an entity | |
227 * revision, just before the field values are deleted from storage. It is only | |
228 * called for entity types that support revisioning. | |
229 */ | |
230 public function deleteRevision(); | |
231 | |
232 /** | |
233 * Generates placeholder field values. | |
234 * | |
235 * Useful when populating site with placeholder content during site building | |
236 * or profiling. | |
237 * | |
238 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition | |
239 * The field definition. | |
240 * | |
241 * @return array | |
242 * An associative array of values. | |
243 */ | |
244 public static function generateSampleValue(FieldDefinitionInterface $field_definition); | |
245 | |
246 /** | |
247 * Defines the storage-level settings for this plugin. | |
248 * | |
249 * @return array | |
250 * A list of default settings, keyed by the setting name. | |
251 */ | |
252 public static function defaultStorageSettings(); | |
253 | |
254 /** | |
255 * Defines the field-level settings for this plugin. | |
256 * | |
257 * @return array | |
258 * A list of default settings, keyed by the setting name. | |
259 */ | |
260 public static function defaultFieldSettings(); | |
261 | |
262 /** | |
263 * Returns a settings array that can be stored as a configuration value. | |
264 * | |
265 * For all use cases where field settings are stored and managed as | |
266 * configuration, this method is used to map from the field type's | |
267 * representation of its settings to a representation compatible with | |
268 * deployable configuration. This includes: | |
269 * - Array keys at any depth must not contain a ".". | |
270 * - Ideally, array keys at any depth are either numeric or can be enumerated | |
271 * as a "mapping" within the configuration schema. While not strictly | |
272 * required, this simplifies configuration translation UIs, configuration | |
273 * migrations between Drupal versions, and other use cases. | |
274 * - To support configuration deployments, references to content entities | |
275 * must use UUIDs rather than local IDs. | |
276 * | |
277 * An example of a conversion between representations might be an | |
278 * "allowed_values" setting that's structured by the field type as a | |
279 * \Drupal\Core\TypedData\OptionsProviderInterface::getPossibleOptions() | |
280 * result (i.e., values as keys and labels as values). For such a use case, | |
281 * in order to comply with the above, this method could convert that | |
282 * representation to a numerically indexed array whose values are sub-arrays | |
283 * with the schema definable keys of "value" and "label". | |
284 * | |
285 * @param array $settings | |
286 * The field's settings in the field type's canonical representation. | |
287 * | |
288 * @return array | |
289 * An array (either the unmodified $settings or a modified representation) | |
290 * that is suitable for storing as a deployable configuration value. | |
291 * | |
292 * @see \Drupal\Core\Config\Config::set() | |
293 */ | |
294 public static function storageSettingsToConfigData(array $settings); | |
295 | |
296 /** | |
297 * Returns a settings array in the field type's canonical representation. | |
298 * | |
299 * This function does the inverse of static::storageSettingsToConfigData(). It's | |
300 * called when loading a field's settings from a configuration object. | |
301 * | |
302 * @param array $settings | |
303 * The field's settings, as it is stored within a configuration object. | |
304 * | |
305 * @return array | |
306 * The settings, in the representation expected by the field type and code | |
307 * that interacts with it. | |
308 * | |
309 * @see \Drupal\Core\Field\FieldItemInterface::storageSettingsToConfigData() | |
310 */ | |
311 public static function storageSettingsFromConfigData(array $settings); | |
312 | |
313 /** | |
314 * Returns a settings array that can be stored as a configuration value. | |
315 * | |
316 * Same as static::storageSettingsToConfigData(), but for the field's settings. | |
317 * | |
318 * @param array $settings | |
319 * The field's settings in the field type's canonical representation. | |
320 * | |
321 * @return array | |
322 * An array (either the unmodified $settings or a modified representation) | |
323 * that is suitable for storing as a deployable configuration value. | |
324 * | |
325 * @see \Drupal\Core\Field\FieldItemInterface::storageSettingsToConfigData() | |
326 */ | |
327 public static function fieldSettingsToConfigData(array $settings); | |
328 | |
329 /** | |
330 * Returns a settings array in the field type's canonical representation. | |
331 * | |
332 * This function does the inverse of static::fieldSettingsToConfigData(). | |
333 * It's called when loading a field's settings from a configuration | |
334 * object. | |
335 * | |
336 * @param array $settings | |
337 * The field's settings, as it is stored within a configuration | |
338 * object. | |
339 * | |
340 * @return array | |
341 * The field settings, in the representation expected by the field type | |
342 * and code that interacts with it. | |
343 * | |
344 * @see \Drupal\Core\Field\FieldItemInterface::fieldSettingsToConfigData() | |
345 */ | |
346 public static function fieldSettingsFromConfigData(array $settings); | |
347 | |
348 /** | |
349 * Returns a form for the storage-level settings. | |
350 * | |
351 * Invoked from \Drupal\field_ui\Form\FieldStorageConfigEditForm to allow | |
352 * administrators to configure storage-level settings. | |
353 * | |
354 * Field storage might reject settings changes that affect the field | |
355 * storage schema if the storage already has data. When the $has_data | |
356 * parameter is TRUE, the form should not allow changing the settings that | |
357 * take part in the schema() method. It is recommended to set #access to | |
358 * FALSE on the corresponding elements. | |
359 * | |
360 * @param array $form | |
361 * The form where the settings form is being included in. | |
362 * @param \Drupal\Core\Form\FormStateInterface $form_state | |
363 * The form state of the (entire) configuration form. | |
364 * @param bool $has_data | |
365 * TRUE if the field already has data, FALSE if not. | |
366 * | |
367 * @return array | |
368 * The form definition for the field settings. | |
369 */ | |
370 public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data); | |
371 | |
372 /** | |
373 * Returns a form for the field-level settings. | |
374 * | |
375 * Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow | |
376 * administrators to configure field-level settings. | |
377 * | |
378 * @param array $form | |
379 * The form where the settings form is being included in. | |
380 * @param \Drupal\Core\Form\FormStateInterface $form_state | |
381 * The form state of the (entire) configuration form. | |
382 * | |
383 * @return array | |
384 * The form definition for the field settings. | |
385 */ | |
386 public function fieldSettingsForm(array $form, FormStateInterface $form_state); | |
387 | |
388 /** | |
389 * Calculates dependencies for field items. | |
390 * | |
391 * Dependencies are saved in the field configuration entity and are used to | |
392 * determine configuration synchronization order. For example, if the field | |
393 * type's default value is a content entity, this method should return an | |
394 * array of dependencies listing the content entities. | |
395 * | |
396 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition | |
397 * The field definition. | |
398 * | |
399 * @return array | |
400 * An array of dependencies grouped by type (config, content, module, | |
401 * theme). For example: | |
402 * @code | |
403 * array( | |
404 * 'config' => array('user.role.anonymous', 'user.role.authenticated'), | |
405 * 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), | |
406 * 'module' => array('node', 'user'), | |
407 * 'theme' => array('seven'), | |
408 * ); | |
409 * @endcode | |
410 * | |
411 * @see \Drupal\Core\Config\Entity\ConfigDependencyManager | |
412 * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName() | |
413 */ | |
414 public static function calculateDependencies(FieldDefinitionInterface $field_definition); | |
415 | |
416 /** | |
417 * Calculates dependencies for field items on the storage level. | |
418 * | |
419 * Dependencies are saved in the field storage configuration entity and are | |
420 * used to determine configuration synchronization order. For example, if the | |
421 * field type storage depends on a particular entity type, this method should | |
422 * return an array of dependencies listing the module that provides the entity | |
423 * type. | |
424 * | |
425 * Dependencies returned from this method are stored in field storage | |
426 * configuration and are always considered hard dependencies. If the | |
427 * dependency is removed the field storage configuration must be deleted. | |
428 * | |
429 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage_definition | |
430 * The field storage definition. | |
431 * | |
432 * @return array | |
433 * An array of dependencies grouped by type (config, content, module, | |
434 * theme). For example: | |
435 * @code | |
436 * [ | |
437 * 'config' => ['user.role.anonymous', 'user.role.authenticated'], | |
438 * 'content' => ['node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'], | |
439 * 'module' => ['node', 'user'], | |
440 * 'theme' => ['seven'], | |
441 * ]; | |
442 * @endcode | |
443 * | |
444 * @see \Drupal\Core\Config\Entity\ConfigDependencyManager | |
445 * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName() | |
446 */ | |
447 public static function calculateStorageDependencies(FieldStorageDefinitionInterface $field_storage_definition); | |
448 | |
449 /** | |
450 * Informs the plugin that a dependency of the field will be deleted. | |
451 * | |
452 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition | |
453 * The field definition. | |
454 * @param array $dependencies | |
455 * An array of dependencies that will be deleted keyed by dependency type. | |
456 * Dependency types are, for example, entity, module and theme. | |
457 * | |
458 * @return bool | |
459 * TRUE if the field definition has been changed as a result, FALSE if not. | |
460 * | |
461 * @see \Drupal\Core\Config\ConfigEntityInterface::onDependencyRemoval() | |
462 */ | |
463 public static function onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies); | |
464 | |
465 } |