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 public function isQueryable();
116 * Returns the human-readable label for the field.
121 public function getLabel();
124 * Returns the human-readable description for the field.
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.
130 * @return string|null
131 * The field description, or NULL if no description is available.
133 public function getDescription();
136 * Gets an options provider for the given field item property.
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.
143 * @return \Drupal\Core\TypedData\OptionsProviderInterface|null
144 * An options provider, or NULL if no options are defined.
146 public function getOptionsProvider($property_name, FieldableEntityInterface $entity);
149 * Returns whether the field can contain multiple items.
152 * TRUE if the field can contain multiple items, FALSE otherwise.
154 public function isMultiple();
157 * Returns the maximum number of items allowed for the field.
159 * Possible values are positive integers or
160 * FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
163 * The field cardinality.
165 public function getCardinality();
168 * Gets the definition of a contained property.
170 * @param string $name
171 * The name of property.
173 * @return \Drupal\Core\TypedData\DataDefinitionInterface|null
174 * The definition of the property or NULL if the property does not exist.
176 public function getPropertyDefinition($name);
179 * Gets an array of property definitions of contained properties.
181 * @return \Drupal\Core\TypedData\DataDefinitionInterface[]
182 * An array of property definitions of contained properties, keyed by
185 public function getPropertyDefinitions();
188 * Returns the names of the field's subproperties.
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.
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.
199 * The property names.
201 public function getPropertyNames();
204 * Returns the name of the main property, if any.
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.
210 * @return string|null
211 * The name of the value property, or NULL if there is none.
213 public function getMainPropertyName();
216 * Returns the ID of the entity type the field is attached to.
218 * This method should not be confused with EntityInterface::getEntityTypeId()
219 * (configurable fields are config entities, and thus implement both
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?".
227 * The entity type ID.
229 public function getTargetEntityTypeId();
232 * Returns the field schema.
234 * Note that this method returns an empty array for computed fields which have
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.
252 public function getSchema();
255 * Returns the field columns, as defined in the field schema.
258 * The array of field columns, keyed by column name, in the same format
259 * returned by getSchema().
261 * @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSchema()
263 public function getColumns();
266 * Returns an array of validation constraints.
268 * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
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.
276 * @see \Symfony\Component\Validator\Constraint
278 public function getConstraints();
281 * Returns a validation constraint.
283 * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
286 * @param string $constraint_name
287 * The name of the constraint, i.e. its plugin id.
290 * A validation constraint definition which can be used for instantiating a
291 * \Symfony\Component\Validator\Constraint object.
293 * @see \Symfony\Component\Validator\Constraint
295 public function getConstraint($constraint_name);
298 * Returns the name of the provider of this field.
301 * The provider name; e.g., the module name.
303 public function getProvider();
306 * Returns the storage behavior for this field.
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.
313 * FALSE if the storage takes care of storing the field, TRUE otherwise.
315 public function hasCustomStorage();
318 * Determines whether the field is a base field.
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
325 * Whether the field is a base field.
327 public function isBaseField();
330 * Returns a unique identifier for the field.
334 public function getUniqueStorageIdentifier();