1b842b9ef56fd9f7e5bf6e249220f50d643e7140
[yaffs-website] / web / core / lib / Drupal / Core / Field / FieldStorageDefinitionInterface.php
1 <?php
2
3 namespace Drupal\Core\Field;
4
5 use Drupal\Core\Cache\CacheableDependencyInterface;
6 use Drupal\Core\Entity\FieldableEntityInterface;
7
8 /**
9  * Defines an interface for entity field storage definitions.
10  *
11  * Field storage definitions represent the part of full field definitions (see
12  * FieldDefinitionInterface) that is responsible for defining how the field is
13  * stored. While field definitions may differ by entity bundle, all of those
14  * bundle fields have to share the same common field storage definition. Thus,
15  * the storage definitions can be defined by entity type only.
16  * The bundle fields corresponding to a field storage definition may provide
17  * additional information; e.g., they may provide bundle-specific settings or
18  * constraints that are not present in the storage definition. However bundle
19  * fields may not override or alter any information provided by the storage
20  * definition except for the label and the description; e.g., any constraints
21  * and settings on the storage definition must be present on the bundle field as
22  * well.
23  *
24  * @see hook_entity_field_storage_info()
25  */
26 interface FieldStorageDefinitionInterface extends CacheableDependencyInterface {
27
28   /**
29    * Value indicating a field accepts an unlimited number of values.
30    */
31   const CARDINALITY_UNLIMITED = -1;
32
33   /**
34    * Returns the machine name of the field.
35    *
36    * This defines how the field data is accessed from the entity. For example,
37    * if the field name is "foo", then $entity->foo returns its data.
38    *
39    * @return string
40    *   The field name.
41    */
42   public function getName();
43
44   /**
45    * Returns the field type.
46    *
47    * @return string
48    *   The field type, i.e. the id of a field type plugin. For example 'text'.
49    *
50    * @see \Drupal\Core\Field\FieldTypePluginManagerInterface
51    */
52   public function getType();
53
54   /**
55    * Returns the storage settings.
56    *
57    * Each field type defines the settings that are meaningful for that type.
58    * For example, a text field can define a 'max_length' setting, and an image
59    * field can define a 'alt_field_required' setting.
60    *
61    * The method always returns an array of all available settings for this field
62    * type, possibly with the default values merged in if values have not been
63    * provided for all available settings.
64    *
65    * @return mixed[]
66    *   An array of key/value pairs.
67    */
68   public function getSettings();
69
70   /**
71    * Returns the value of a given storage setting.
72    *
73    * @param string $setting_name
74    *   The setting name.
75    *
76    * @return mixed
77    *   The setting value.
78    */
79   public function getSetting($setting_name);
80
81   /**
82    * Returns whether the field supports translation.
83    *
84    * @return bool
85    *   TRUE if the field supports translation.
86    */
87   public function isTranslatable();
88
89   /**
90    * Sets whether the field supports translation.
91    *
92    * @param bool $translatable
93    *   Whether the field supports translation.
94    *
95    * @return $this
96    */
97   public function setTranslatable($translatable);
98
99   /**
100    * Returns whether the field is revisionable.
101    *
102    * @return bool
103    *   TRUE if the field is revisionable.
104    */
105   public function isRevisionable();
106
107   /**
108    * Determines whether the field is queryable via QueryInterface.
109    *
110    * @return bool
111    *   TRUE if the field is queryable.
112    */
113   public function isQueryable();
114
115   /**
116    * Returns the human-readable label for the field.
117    *
118    * @return string
119    *   The field label.
120    */
121   public function getLabel();
122
123   /**
124    * Returns the human-readable description for the field.
125    *
126    * This is displayed in addition to the label in places where additional
127    * descriptive information is helpful. For example, as help text below the
128    * form element in entity edit forms.
129    *
130    * @return string|null
131    *   The field description, or NULL if no description is available.
132    */
133   public function getDescription();
134
135   /**
136    * Gets an options provider for the given field item property.
137    *
138    * @param string $property_name
139    *   The name of the property to get options for; e.g., 'value'.
140    * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
141    *   The entity for which the options should be provided.
142    *
143    * @return \Drupal\Core\TypedData\OptionsProviderInterface|null
144    *   An options provider, or NULL if no options are defined.
145    */
146   public function getOptionsProvider($property_name, FieldableEntityInterface $entity);
147
148   /**
149    * Returns whether the field can contain multiple items.
150    *
151    * @return bool
152    *   TRUE if the field can contain multiple items, FALSE otherwise.
153    */
154   public function isMultiple();
155
156   /**
157    * Returns the maximum number of items allowed for the field.
158    *
159    * Possible values are positive integers or
160    * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
161    *
162    * @return int
163    *   The field cardinality.
164    */
165   public function getCardinality();
166
167   /**
168    * Gets the definition of a contained property.
169    *
170    * @param string $name
171    *   The name of property.
172    *
173    * @return \Drupal\Core\TypedData\DataDefinitionInterface|null
174    *   The definition of the property or NULL if the property does not exist.
175    */
176   public function getPropertyDefinition($name);
177
178   /**
179    * Gets an array of property definitions of contained properties.
180    *
181    * @return \Drupal\Core\TypedData\DataDefinitionInterface[]
182    *   An array of property definitions of contained properties, keyed by
183    *   property name.
184    */
185   public function getPropertyDefinitions();
186
187   /**
188    * Returns the names of the field's subproperties.
189    *
190    * A field is a list of items, and each item can contain one or more
191    * properties. All items for a given field contain the same property names,
192    * but the values can be different for each item.
193    *
194    * For example, an email field might just contain a single 'value' property,
195    * while a link field might contain 'title' and 'url' properties, and a text
196    * field might contain 'value', 'summary', and 'format' properties.
197    *
198    * @return string[]
199    *   The property names.
200    */
201   public function getPropertyNames();
202
203   /**
204    * Returns the name of the main property, if any.
205    *
206    * Some field items consist mainly of one main property, e.g. the value of a
207    * text field or the @code target_id @endcode of an entity reference. If the
208    * field item has no main property, the method returns NULL.
209    *
210    * @return string|null
211    *   The name of the value property, or NULL if there is none.
212    */
213   public function getMainPropertyName();
214
215   /**
216    * Returns the ID of the entity type the field is attached to.
217    *
218    * This method should not be confused with EntityInterface::getEntityTypeId()
219    * (configurable fields are config entities, and thus implement both
220    * interfaces):
221    *   - FieldStorageDefinitionInterface::getTargetEntityTypeId() answers "as a
222    *     field storage, which entity type are you attached to?".
223    *   - EntityInterface::getEntityTypeId() answers "as a (config) entity, what
224    *     is your own entity type?".
225    *
226    * @return string
227    *   The entity type ID.
228    */
229   public function getTargetEntityTypeId();
230
231   /**
232    * Returns the field schema.
233    *
234    * Note that this method returns an empty array for computed fields which have
235    * no schema.
236    *
237    * @return array[]
238    *   The field schema, as an array of key/value pairs in the format returned
239    *   by \Drupal\Core\Field\FieldItemInterface::schema():
240    *   - columns: An array of Schema API column specifications, keyed by column
241    *     name. This specifies what comprises a single value for a given field.
242    *     No assumptions should be made on how storage backends internally use
243    *     the original column name to structure their storage.
244    *   - indexes: An array of Schema API index definitions. Some storage
245    *     backends might not support indexes.
246    *   - unique keys: An array of Schema API unique key definitions.  Some
247    *     storage backends might not support unique keys.
248    *   - foreign keys: An array of Schema API foreign key definitions. Note,
249    *     however, that depending on the storage backend specified for the field,
250    *     the field data is not necessarily stored in SQL.
251    */
252   public function getSchema();
253
254   /**
255    * Returns the field columns, as defined in the field schema.
256    *
257    * @return array[]
258    *   The array of field columns, keyed by column name, in the same format
259    *   returned by getSchema().
260    *
261    * @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSchema()
262    */
263   public function getColumns();
264
265   /**
266    * Returns an array of validation constraints.
267    *
268    * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
269    * details.
270    *
271    * @return array[]
272    *   An array of validation constraint definitions, keyed by constraint name.
273    *   Each constraint definition can be used for instantiating
274    *   \Symfony\Component\Validator\Constraint objects.
275    *
276    * @see \Symfony\Component\Validator\Constraint
277    */
278   public function getConstraints();
279
280   /**
281    * Returns a validation constraint.
282    *
283    * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
284    * details.
285    *
286    * @param string $constraint_name
287    *   The name of the constraint, i.e. its plugin id.
288    *
289    * @return array
290    *   A validation constraint definition which can be used for instantiating a
291    *   \Symfony\Component\Validator\Constraint object.
292    *
293    * @see \Symfony\Component\Validator\Constraint
294    */
295   public function getConstraint($constraint_name);
296
297   /**
298    * Returns the name of the provider of this field.
299    *
300    * @return string
301    *   The provider name; e.g., the module name.
302    */
303   public function getProvider();
304
305   /**
306    * Returns the storage behavior for this field.
307    *
308    * Indicates whether the entity type's storage should take care of storing the
309    * field values or whether it is handled separately; e.g. by the
310    * module providing the field.
311    *
312    * @return bool
313    *   FALSE if the storage takes care of storing the field, TRUE otherwise.
314    */
315   public function hasCustomStorage();
316
317   /**
318    * Determines whether the field is a base field.
319    *
320    * Base fields are not specific to a given bundle or a set of bundles. This
321    * excludes configurable fields, as they are always attached to a specific
322    * bundle.
323    *
324    * @return bool
325    *   Whether the field is a base field.
326    */
327   public function isBaseField();
328
329   /**
330    * Returns a unique identifier for the field.
331    *
332    * @return string
333    */
334   public function getUniqueStorageIdentifier();
335
336 }