3 namespace Drupal\Core\Field;
5 use Drupal\Core\Cache\CacheableDependencyInterface;
6 use Drupal\Core\Entity\FieldableEntityInterface;
9 * Defines an interface for entity field storage definitions.
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
24 * @see hook_entity_field_storage_info()
26 interface FieldStorageDefinitionInterface extends CacheableDependencyInterface {
29 * Value indicating a field accepts an unlimited number of values.
31 const CARDINALITY_UNLIMITED = -1;
34 * Returns the machine name of the field.
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.
42 public function getName();
45 * Returns the field type.
48 * The field type, i.e. the id of a field type plugin. For example 'text'.
50 * @see \Drupal\Core\Field\FieldTypePluginManagerInterface
52 public function getType();
55 * Returns the storage settings.
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.
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.
66 * An array of key/value pairs.
68 public function getSettings();
71 * Returns the value of a given storage setting.
73 * @param string $setting_name
79 public function getSetting($setting_name);
82 * Returns whether the field supports translation.
85 * TRUE if the field supports translation.
87 public function isTranslatable();
90 * Sets whether the field supports translation.
92 * @param bool $translatable
93 * Whether the field supports translation.
97 public function setTranslatable($translatable);
100 * Returns whether the field is revisionable.
103 * TRUE if the field is revisionable.
105 public function isRevisionable();
108 * Determines whether the field is queryable via QueryInterface.
111 * TRUE if the field is queryable.
113 * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use
114 * \Drupal\Core\Field\FieldStorageDefinitionInterface::hasCustomStorage()
117 * @see https://www.drupal.org/node/2856563
119 public function isQueryable();
122 * Returns the human-readable label for the field.
127 public function getLabel();
130 * Returns the human-readable description for the field.
132 * This is displayed in addition to the label in places where additional
133 * descriptive information is helpful. For example, as help text below the
134 * form element in entity edit forms.
136 * @return string|null
137 * The field description, or NULL if no description is available.
139 public function getDescription();
142 * Gets an options provider for the given field item property.
144 * @param string $property_name
145 * The name of the property to get options for; e.g., 'value'.
146 * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
147 * The entity for which the options should be provided.
149 * @return \Drupal\Core\TypedData\OptionsProviderInterface|null
150 * An options provider, or NULL if no options are defined.
152 public function getOptionsProvider($property_name, FieldableEntityInterface $entity);
155 * Returns whether the field can contain multiple items.
158 * TRUE if the field can contain multiple items, FALSE otherwise.
160 public function isMultiple();
163 * Returns the maximum number of items allowed for the field.
165 * Possible values are positive integers or
166 * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
169 * The field cardinality.
171 public function getCardinality();
174 * Gets the definition of a contained property.
176 * @param string $name
177 * The name of property.
179 * @return \Drupal\Core\TypedData\DataDefinitionInterface|null
180 * The definition of the property or NULL if the property does not exist.
182 public function getPropertyDefinition($name);
185 * Gets an array of property definitions of contained properties.
187 * @return \Drupal\Core\TypedData\DataDefinitionInterface[]
188 * An array of property definitions of contained properties, keyed by
191 public function getPropertyDefinitions();
194 * Returns the names of the field's subproperties.
196 * A field is a list of items, and each item can contain one or more
197 * properties. All items for a given field contain the same property names,
198 * but the values can be different for each item.
200 * For example, an email field might just contain a single 'value' property,
201 * while a link field might contain 'title' and 'url' properties, and a text
202 * field might contain 'value', 'summary', and 'format' properties.
205 * The property names.
207 public function getPropertyNames();
210 * Returns the name of the main property, if any.
212 * Some field items consist mainly of one main property, e.g. the value of a
213 * text field or the @code target_id @endcode of an entity reference. If the
214 * field item has no main property, the method returns NULL.
216 * @return string|null
217 * The name of the value property, or NULL if there is none.
219 public function getMainPropertyName();
222 * Returns the ID of the entity type the field is attached to.
224 * This method should not be confused with EntityInterface::getEntityTypeId()
225 * (configurable fields are config entities, and thus implement both
227 * - FieldStorageDefinitionInterface::getTargetEntityTypeId() answers "as a
228 * field storage, which entity type are you attached to?".
229 * - EntityInterface::getEntityTypeId() answers "as a (config) entity, what
230 * is your own entity type?".
233 * The entity type ID.
235 public function getTargetEntityTypeId();
238 * Returns the field schema.
240 * Note that this method returns an empty array for computed fields which have
244 * The field schema, as an array of key/value pairs in the format returned
245 * by \Drupal\Core\Field\FieldItemInterface::schema():
246 * - columns: An array of Schema API column specifications, keyed by column
247 * name. This specifies what comprises a single value for a given field.
248 * No assumptions should be made on how storage backends internally use
249 * the original column name to structure their storage.
250 * - indexes: An array of Schema API index definitions. Some storage
251 * backends might not support indexes.
252 * - unique keys: An array of Schema API unique key definitions. Some
253 * storage backends might not support unique keys.
254 * - foreign keys: An array of Schema API foreign key definitions. Note,
255 * however, that depending on the storage backend specified for the field,
256 * the field data is not necessarily stored in SQL.
258 public function getSchema();
261 * Returns the field columns, as defined in the field schema.
264 * The array of field columns, keyed by column name, in the same format
265 * returned by getSchema().
267 * @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSchema()
269 public function getColumns();
272 * Returns an array of validation constraints.
274 * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
278 * An array of validation constraint definitions, keyed by constraint name.
279 * Each constraint definition can be used for instantiating
280 * \Symfony\Component\Validator\Constraint objects.
282 * @see \Symfony\Component\Validator\Constraint
284 public function getConstraints();
287 * Returns a validation constraint.
289 * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
292 * @param string $constraint_name
293 * The name of the constraint, i.e. its plugin id.
296 * A validation constraint definition which can be used for instantiating a
297 * \Symfony\Component\Validator\Constraint object.
299 * @see \Symfony\Component\Validator\Constraint
301 public function getConstraint($constraint_name);
304 * Returns the name of the provider of this field.
307 * The provider name; e.g., the module name.
309 public function getProvider();
312 * Returns the storage behavior for this field.
314 * Indicates whether the entity type's storage should take care of storing the
315 * field values or whether it is handled separately; e.g. by the
316 * module providing the field.
319 * FALSE if the storage takes care of storing the field, TRUE otherwise.
321 public function hasCustomStorage();
324 * Determines whether the field is a base field.
326 * Base fields are not specific to a given bundle or a set of bundles. This
327 * excludes configurable fields, as they are always attached to a specific
331 * Whether the field is a base field.
333 public function isBaseField();
336 * Returns a unique identifier for the field.
340 public function getUniqueStorageIdentifier();