class FileItem extends EntityReferenceItem (View source)

Plugin implementation of the 'file' field type.

Traits

Provides dependency injection friendly methods for serialization.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Wrapper methods for classes that needs typed data manager object.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected TypedDataManagerInterface $typedDataManager

The typed data manager used for creating the data types.

from  TypedDataTrait
protected ComplexDataDefinitionInterface $definition

The data definition.

from  Map
protected string $name

The property name.

from  TypedData
protected TraversableTypedDataInterface|null $parent

The parent typed data object.

from  TypedData
protected array $values

An array of values for the contained properties.

from  Map
protected TypedDataInterface[] $properties

The array of properties.

from  Map

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

$this
setTypedDataManager(TypedDataManagerInterface $typed_data_manager)

Sets the typed data manager.

getTypedDataManager()

Gets the typed data manager.

static 
createInstance(DataDefinitionInterface $definition, string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

__construct(DataDefinitionInterface $definition, string $name = NULL, TypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

getDataDefinition()

Gets the data definition.

mixed
getValue()

Gets the data value.

setValue(array|null $values, bool $notify = TRUE)

Overrides \Drupal\Core\TypedData\TypedData::setValue().

string
getString()

Returns a string representation of the data.

from  Map
array
getConstraints()

Gets a list of validation constraints.

ConstraintViolationListInterface
validate()

Validates the currently set data value.

$this
applyDefaultValue(bool $notify = TRUE)

Applies the default value.

from  Map
setContext(string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)

Sets the context of a property or item via a context aware parent.

string|int|null
getName()

Returns the name of a property or item.

getRoot()

Returns the root of the typed data tree.

string
getPropertyPath()

Returns the property path of the data.

getParent()

Returns the parent data structure; i.e. either complex data or a list.

get($property_name)

Gets a property object.

from  Map
$this
set($property_name, $value, bool $notify = TRUE)

Sets a property value.

from  Map
writePropertyValue(string $property_name, $value)

Writes the value of a property without handling changes.

getProperties(bool $include_computed = FALSE)

Gets an array of property objects.

from  Map
array
toArray()

Returns an array of all property values.

from  Map
getIterator()

{@inheritdoc}

from  Map
bool
isEmpty()

Determines whether the data structure is empty.

__clone()

Magic method: Implements a deep clone.

from  Map
onChange($property_name, bool $notify = TRUE)

React to changes to a child property or item.

static array
defaultStorageSettings()

Defines the storage-level settings for this plugin.

static array
defaultFieldSettings()

Defines the field-level settings for this plugin.

static string|null
mainPropertyName()

Returns the name of the main property, if any.

getEntity()

Gets the entity that field belongs to.

string
getLangcode()

Gets the langcode of the field values held in the object.

getFieldDefinition()

Gets the field definition.

array
getSettings()

Returns the array of field settings.

mixed
getSetting(string $setting_name)

Returns the value of a field setting.

mixed
__get($name)

Magic method: Gets a property value.

__set($name, mixed $value)

Magic method: Sets a property value.

bool
__isset($name)

Magic method: Determines whether a property is set.

__unset($name)

Magic method: Unsets a property.

array
view(string|array $display_options = [])

Returns a renderable array for a single field item.

preSave()

Defines custom presave behavior for field values.

bool
postSave(bool $update)

Defines custom post-save behavior for field values.

delete()

Defines custom delete behavior for field values.

static array
generateSampleValue(FieldDefinitionInterface $field_definition)

Generates placeholder field values.

deleteRevision()

Defines custom revision delete behavior for field values.

array
storageSettingsForm(array $form, FormStateInterface $form_state, bool $has_data)

Returns a form for the storage-level settings.

array
fieldSettingsForm(array $form, FormStateInterface $form_state)

Returns a form for the field-level settings.

static array
storageSettingsToConfigData(array $settings)

Returns a settings array that can be stored as a configuration value.

static array
storageSettingsFromConfigData(array $settings)

Returns a settings array in the field type's canonical representation.

static array
fieldSettingsToConfigData(array $settings)

Returns a settings array that can be stored as a configuration value.

static array
fieldSettingsFromConfigData(array $settings)

Returns a settings array in the field type's canonical representation.

static array
calculateDependencies(FieldDefinitionInterface $field_definition)

Calculates dependencies for field items.

static array
calculateStorageDependencies(FieldStorageDefinitionInterface $field_definition)

Calculates dependencies for field items on the storage level.

static bool
onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies)

Informs the plugin that a dependency of the field will be deleted.

propertyDefinitions(FieldStorageDefinitionInterface $field_definition)

Defines field item properties.

static array
schema(FieldStorageDefinitionInterface $field_definition)

Returns the schema for the field.

static string|null
getRandomBundle(EntityTypeInterface $entity_type, array $selection_settings)

Gets a bundle for a given entity type and selection options.

static 
fieldSettingsFormValidate(array $form, FormStateInterface $form_state)

Form element validation handler; Invokes selection plugin's validation.

bool
hasNewEntity()

Determines whether the item holds an unsaved entity.

array
getPossibleValues(AccountInterface $account = NULL)

Returns an array of possible values.

array
getPossibleOptions(AccountInterface $account = NULL)

Returns an array of possible values with labels for display.

array
getSettableValues(AccountInterface $account = NULL)

Returns an array of settable values.

array
getSettableOptions(AccountInterface $account = NULL)

Returns an array of settable values with labels for display.

static 
fieldSettingsAjaxProcess($form, FormStateInterface $form_state)

Render API callback: Processes the field settings form.

static 
fieldSettingsAjaxProcessElement($element, $main_form)

Adds entity_reference specific properties to AJAX form elements from the field settings form.

static 
formProcessMergeParent($element)

Render API callback: Moves entity_reference specific Form API elements (i.e. 'handler_settings') up a level for easier processing by the validation and submission handlers.

static 
settingsAjax($form, FormStateInterface $form_state)

Ajax callback for the handler settings form.

static 
settingsAjaxSubmit($form, FormStateInterface $form_state)

Submit handler for the non-JS case.

static array[]
getPreconfiguredOptions()

Returns preconfigured field options for a field type.

static 
validateDirectory($element, FormStateInterface $form_state)

Form API callback.

static 
validateExtensions($element, FormStateInterface $form_state)

Form API callback.

static 
validateMaxFilesize($element, FormStateInterface $form_state)

Form API callback.

string
getUploadLocation(array $data = [])

Determines the URI for a file field.

static string
doGetUploadLocation(array $settings, array $data = [])

Determines the URI for a file field.

array
getUploadValidators()

Retrieves the upload validators for a file field.

bool
isDisplayed()

Determines whether an item should be displayed when rendering the field.

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

$this setTypedDataManager(TypedDataManagerInterface $typed_data_manager)

Sets the typed data manager.

Parameters

TypedDataManagerInterface $typed_data_manager

The typed data manager.

Return Value

$this

TypedDataManagerInterface getTypedDataManager()

Gets the typed data manager.

Return Value

TypedDataManagerInterface

The typed data manager.

static createInstance(DataDefinitionInterface $definition, string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

Parameters

DataDefinitionInterface $definition

The data definition.

string|null $name

(optional) The name of the created property, or NULL if it is the root of a typed data tree. Defaults to NULL.

TraversableTypedDataInterface $parent

(optional) The parent object of the data property, or NULL if it is the root of a typed data tree. Defaults to NULL.

__construct(DataDefinitionInterface $definition, string $name = NULL, TypedDataInterface $parent = NULL)

Constructs a TypedData object given its definition and context.

Parameters

DataDefinitionInterface $definition

The data definition.

string $name

(optional) The name of the created property, or NULL if it is the root of a typed data tree. Defaults to NULL.

TypedDataInterface $parent

(optional) The parent object of the data property, or NULL if it is the root of a typed data tree. Defaults to NULL.

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

DataDefinitionInterface getDataDefinition()

Gets the data definition.

Return Value

DataDefinitionInterface

The data definition object.

mixed getValue()

Gets the data value.

Return Value

mixed

The data value.

setValue(array|null $values, bool $notify = TRUE)

Overrides \Drupal\Core\TypedData\TypedData::setValue().

Parameters

array|null $values

An array of property values.

bool $notify

(optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

string getString()

Returns a string representation of the data.

Return Value

string

The string representation of the data.

array getConstraints()

Gets a list of validation constraints.

Return Value

array

Array of constraints, each being an instance of \Symfony\Component\Validator\Constraint.

ConstraintViolationListInterface validate()

Validates the currently set data value.

Return Value

ConstraintViolationListInterface

A list of constraint violations. If the list is empty, validation succeeded.

$this applyDefaultValue(bool $notify = TRUE)

Applies the default value.

Parameters

bool $notify

(optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Return Value

$this

Returns itself to allow for chaining.

setContext(string|null $name = NULL, TraversableTypedDataInterface $parent = NULL)

Sets the context of a property or item via a context aware parent.

This method is supposed to be called by the factory only.

Parameters

string|null $name

(optional) The name of the property or the delta of the list item, or NULL if it is the root of a typed data tree. Defaults to NULL.

TraversableTypedDataInterface $parent

(optional) The parent object of the data property, or NULL if it is the root of a typed data tree. Defaults to NULL.

string|int|null getName()

Returns the name of a property or item.

Return Value

string|int|null

If the data is a property of some complex data, the name of the property. If the data is an item of a list, the name is the numeric position of the item in the list, starting with 0. Otherwise, NULL is returned.

TraversableTypedDataInterface getRoot()

Returns the root of the typed data tree.

Returns the root data for a tree of typed data objects; e.g. for an entity field item the root of the tree is its parent entity object.

Return Value

TraversableTypedDataInterface

The root data structure, either complex data or a list.

string getPropertyPath()

Returns the property path of the data.

The trail of property names relative to the root of the typed data tree, separated by dots; e.g. 'field_text.0.format'.

Return Value

string

The property path relative to the root of the typed tree, or an empty string if this is the root.

TraversableTypedDataInterface|null getParent()

Returns the parent data structure; i.e. either complex data or a list.

Return Value

TraversableTypedDataInterface|null

The parent data structure, either complex data or a list; or NULL if this is the root of the typed data tree.

TypedDataInterface get($property_name)

Gets a property object.

Parameters

$property_name

The name of the property to get; e.g., 'title' or 'name'.

Return Value

TypedDataInterface

The property object.

Exceptions

InvalidArgumentException
MissingDataException

$this set($property_name, $value, bool $notify = TRUE)

Sets a property value.

Parameters

$property_name

The name of the property to set; e.g., 'title' or 'name'.

$value

The value to set, or NULL to unset the property.

bool $notify

(optional) Whether to notify the parent object of the change. Defaults to TRUE. If the update stems from a parent object, set it to FALSE to avoid being notified again.

Return Value

$this

Exceptions

InvalidArgumentException
MissingDataException

protected writePropertyValue(string $property_name, $value)

Writes the value of a property without handling changes.

Implementations of onChange() should use this method instead of set() in order to avoid onChange() being triggered again.

Parameters

string $property_name

The name of the property to be written.

$value

The value to set.

TypedDataInterface[] getProperties(bool $include_computed = FALSE)

Gets an array of property objects.

Parameters

bool $include_computed

If set to TRUE, computed properties are included. Defaults to FALSE.

Return Value

TypedDataInterface[]

An array of property objects implementing the TypedDataInterface, keyed by property name.

Exceptions

MissingDataException

array toArray()

Returns an array of all property values.

Gets an array of plain property values including all not-computed properties.

Return Value

array

An array of property values, keyed by property name.

Exceptions

MissingDataException

getIterator()

{@inheritdoc}

bool isEmpty()

Determines whether the data structure is empty.

Return Value

bool

TRUE if the data structure is empty, FALSE otherwise.

__clone()

Magic method: Implements a deep clone.

onChange($property_name, bool $notify = TRUE)

React to changes to a child property or item.

Note that this is invoked after any changes have been applied.

Parameters

$property_name

The name of the property.

bool $notify

(optional) Whether to forward the notification to the parent. Defaults to TRUE. By passing FALSE, overrides of this method can re-use the logic of parent classes without triggering notification.

static array defaultStorageSettings()

Defines the storage-level settings for this plugin.

Return Value

array

A list of default settings, keyed by the setting name.

static array defaultFieldSettings()

Defines the field-level settings for this plugin.

Return Value

array

A list of default settings, keyed by the setting name.

static string|null mainPropertyName()

Returns the name of the main property, if any.

Some field items consist mainly of one main property, e.g. the value of a text field or the target_id of an entity reference. If the field item has no main property, the method returns NULL.

Return Value

string|null

The name of the value property, or NULL if there is none.

FieldableEntityInterface getEntity()

Gets the entity that field belongs to.

Return Value

FieldableEntityInterface

The entity object.

string getLangcode()

Gets the langcode of the field values held in the object.

Return Value

string

The langcode.

FieldDefinitionInterface getFieldDefinition()

Gets the field definition.

Return Value

FieldDefinitionInterface

The field definition.

protected array getSettings()

Returns the array of field settings.

Return Value

array

The array of settings.

protected mixed getSetting(string $setting_name)

Returns the value of a field setting.

Parameters

string $setting_name

The setting name.

Return Value

mixed

The setting value.

mixed __get($name)

Magic method: Gets a property value.

Parameters

$name

Return Value

mixed

The property value.

Exceptions

InvalidArgumentException

__set($name, mixed $value)

Magic method: Sets a property value.

Parameters

$name
mixed $value

The value to set, or NULL to unset the property. Optionally, a typed data object implementing Drupal\Core\TypedData\TypedDataInterface may be passed instead of a plain value.

Exceptions

InvalidArgumentException

bool __isset($name)

Magic method: Determines whether a property is set.

Parameters

$name

Return Value

bool

Returns TRUE if the property exists and is set, FALSE otherwise.

__unset($name)

Magic method: Unsets a property.

Parameters

$name

array view(string|array $display_options = [])

Returns a renderable array for a single field item.

Parameters

string|array $display_options

Can be either the name of a view mode, or an array of display settings. See EntityViewBuilderInterface::viewField() for more information.

Return Value

array

A renderable array for the field item.

preSave()

Defines custom presave behavior for field values.

This method is called during the process of saving an entity, just before values are written into storage. When storing a new entity, its identifier will not be available yet. This should be used to massage item property values or perform any other operation that needs to happen before values are stored. For instance this is the proper phase to auto-create a new entity for an entity reference field item, because this way it will be possible to store the referenced entity identifier.

bool postSave(bool $update)

Defines custom post-save behavior for field values.

This method is called during the process of saving an entity, just after values are written into storage. This is useful mostly when the business logic to be implemented always requires the entity identifier, even when storing a new entity. For instance, when implementing circular entity references, the referenced entity will be created on pre-save with a dummy value for the referring entity identifier, which will be updated with the actual one on post-save.

In the rare cases where item properties depend on the entity identifier, massaging logic will have to be implemented on post-save and returning TRUE will allow them to be rewritten to the storage with the updated values.

Parameters

bool $update

Specifies whether the entity is being updated or created.

Return Value

bool

Whether field items should be rewritten to the storage as a consequence of the logic implemented by the custom behavior.

delete()

Defines custom delete behavior for field values.

This method is called during the process of deleting an entity, just before values are deleted from storage.

static array generateSampleValue(FieldDefinitionInterface $field_definition)

Generates placeholder field values.

Useful when populating site with placeholder content during site building or profiling.

Parameters

FieldDefinitionInterface $field_definition

The field definition.

Return Value

array

An associative array of values.

deleteRevision()

Defines custom revision delete behavior for field values.

This method is called from during the process of deleting an entity revision, just before the field values are deleted from storage. It is only called for entity types that support revisioning.

array storageSettingsForm(array $form, FormStateInterface $form_state, bool $has_data)

Returns a form for the storage-level settings.

Invoked from \Drupal\field_ui\Form\FieldStorageConfigEditForm to allow administrators to configure storage-level settings.

Field storage might reject settings changes that affect the field storage schema if the storage already has data. When the $has_data parameter is TRUE, the form should not allow changing the settings that take part in the schema() method. It is recommended to set #access to FALSE on the corresponding elements.

Parameters

array $form

The form where the settings form is being included in.

FormStateInterface $form_state

The form state of the (entire) configuration form.

bool $has_data

TRUE if the field already has data, FALSE if not.

Return Value

array

The form definition for the field settings.

array fieldSettingsForm(array $form, FormStateInterface $form_state)

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

array $form

The form where the settings form is being included in.

FormStateInterface $form_state

The form state of the (entire) configuration form.

Return Value

array

The form definition for the field settings.

static array storageSettingsToConfigData(array $settings)

Returns a settings array that can be stored as a configuration value.

For all use cases where field settings are stored and managed as configuration, this method is used to map from the field type's representation of its settings to a representation compatible with deployable configuration. This includes:

  • Array keys at any depth must not contain a ".".
  • Ideally, array keys at any depth are either numeric or can be enumerated as a "mapping" within the configuration schema. While not strictly required, this simplifies configuration translation UIs, configuration migrations between Drupal versions, and other use cases.
  • To support configuration deployments, references to content entities must use UUIDs rather than local IDs.

An example of a conversion between representations might be an "allowed_values" setting that's structured by the field type as a \Drupal\Core\TypedData\OptionsProviderInterface::getPossibleOptions() result (i.e., values as keys and labels as values). For such a use case, in order to comply with the above, this method could convert that representation to a numerically indexed array whose values are sub-arrays with the schema definable keys of "value" and "label".

Parameters

array $settings

The field's settings in the field type's canonical representation.

Return Value

array

An array (either the unmodified $settings or a modified representation) that is suitable for storing as a deployable configuration value.

static array storageSettingsFromConfigData(array $settings)

Returns a settings array in the field type's canonical representation.

This function does the inverse of static::storageSettingsToConfigData(). It's called when loading a field's settings from a configuration object.

Parameters

array $settings

The field's settings, as it is stored within a configuration object.

Return Value

array

The settings, in the representation expected by the field type and code that interacts with it.

static array fieldSettingsToConfigData(array $settings)

Returns a settings array that can be stored as a configuration value.

Same as static::storageSettingsToConfigData(), but for the field's settings.

Parameters

array $settings

The field's settings in the field type's canonical representation.

Return Value

array

An array (either the unmodified $settings or a modified representation) that is suitable for storing as a deployable configuration value.

static array fieldSettingsFromConfigData(array $settings)

Returns a settings array in the field type's canonical representation.

This function does the inverse of static::fieldSettingsToConfigData(). It's called when loading a field's settings from a configuration object.

Parameters

array $settings

The field's settings, as it is stored within a configuration object.

Return Value

array

The field settings, in the representation expected by the field type and code that interacts with it.

static array calculateDependencies(FieldDefinitionInterface $field_definition)

Calculates dependencies for field items.

Dependencies are saved in the field configuration entity and are used to determine configuration synchronization order. For example, if the field type's default value is a content entity, this method should return an array of dependencies listing the content entities.

Parameters

FieldDefinitionInterface $field_definition

The field definition.

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code array( 'config' => array('user.role.anonymous', 'user.role.authenticated'), 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), 'module' => array('node', 'user'), 'theme' => array('seven'), ); @endcode

static array calculateStorageDependencies(FieldStorageDefinitionInterface $field_definition)

Calculates dependencies for field items on the storage level.

Dependencies are saved in the field storage configuration entity and are used to determine configuration synchronization order. For example, if the field type storage depends on a particular entity type, this method should return an array of dependencies listing the module that provides the entity type.

Dependencies returned from this method are stored in field storage configuration and are always considered hard dependencies. If the dependency is removed the field storage configuration must be deleted.

Parameters

FieldStorageDefinitionInterface $field_definition

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code [ 'config' => ['user.role.anonymous', 'user.role.authenticated'], 'content' => ['node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'], 'module' => ['node', 'user'], 'theme' => ['seven'], ]; @endcode

static bool onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies)

Informs the plugin that a dependency of the field will be deleted.

Parameters

FieldDefinitionInterface $field_definition

The field definition.

array $dependencies

An array of dependencies that will be deleted keyed by dependency type. Dependency types are, for example, entity, module and theme.

Return Value

bool

TRUE if the field definition has been changed as a result, FALSE if not.

static DataDefinitionInterface[] propertyDefinitions(FieldStorageDefinitionInterface $field_definition)

Defines field item properties.

Properties that are required to constitute a valid, non-empty item should be denoted with \Drupal\Core\TypedData\DataDefinition::setRequired().

Parameters

FieldStorageDefinitionInterface $field_definition

Return Value

DataDefinitionInterface[]

An array of property definitions of contained properties, keyed by property name.

static array schema(FieldStorageDefinitionInterface $field_definition)

Returns the schema for the field.

This method is static because the field schema information is needed on creation of the field. FieldItemInterface objects instantiated at that time are not reliable as field settings might be missing.

Computed fields having no schema should return an empty array.

Parameters

FieldStorageDefinitionInterface $field_definition

The field definition.

Return Value

array

An empty array if there is no schema, or an associative array with the following key/value pairs:

  • columns: An array of Schema API column specifications, keyed by column name. The columns need to be a subset of the properties defined in propertyDefinitions(). The 'not null' property is ignored if present, as it is determined automatically by the storage controller depending on the table layout and the property definitions. It is recommended to avoid having the column definitions depend on field settings when possible. No assumptions should be made on how storage engines internally use the original column name to structure their storage.
  • unique keys: (optional) An array of Schema API unique key definitions. Only columns that appear in the 'columns' array are allowed.
  • indexes: (optional) An array of Schema API index definitions. Only columns that appear in the 'columns' array are allowed. Those indexes will be used as default indexes. Field definitions can specify additional indexes or, at their own risk, modify the default indexes specified by the field-type module. Some storage engines might not support indexes.
  • foreign keys: (optional) An array of Schema API foreign key definitions. Note, however, that the field data is not necessarily stored in SQL. Also, the possible usage is limited, as you cannot specify another field as related, only existing SQL tables, such as {taxonomy_term_data}.

static protected string|null getRandomBundle(EntityTypeInterface $entity_type, array $selection_settings)

Gets a bundle for a given entity type and selection options.

Parameters

EntityTypeInterface $entity_type

The entity type.

array $selection_settings

An array of selection settings.

Return Value

string|null

Either the bundle string, or NULL if there is no bundle.

static fieldSettingsFormValidate(array $form, FormStateInterface $form_state)

Form element validation handler; Invokes selection plugin's validation.

Parameters

array $form

The form where the settings form is being included in.

FormStateInterface $form_state

The form state of the (entire) configuration form.

bool hasNewEntity()

Determines whether the item holds an unsaved entity.

This is notably used for "autocreate" widgets, and more generally to support referencing freshly created entities (they will get saved automatically as the hosting entity gets saved).

Return Value

bool

TRUE if the item holds an unsaved entity.

array getPossibleValues(AccountInterface $account = NULL)

Returns an array of possible values.

If the optional $account parameter is passed, then the array is filtered to values viewable by the account.

Parameters

AccountInterface $account

(optional) The user account for which to filter the possible values. If omitted, all possible values are returned.

Return Value

array

An array of possible values.

array getPossibleOptions(AccountInterface $account = NULL)

Returns an array of possible values with labels for display.

If the optional $account parameter is passed, then the array is filtered to values viewable by the account.

Parameters

AccountInterface $account

(optional) The user account for which to filter the possible options. If omitted, all possible options are returned.

Return Value

array

An array of possible options for the object that may be used in an Options widget, for example when existing data should be filtered. It may either be a flat array of option labels keyed by values, or a two-dimensional array of option groups (array of flat option arrays, keyed by option group label). Note that labels should NOT be sanitized.

array getSettableValues(AccountInterface $account = NULL)

Returns an array of settable values.

If the optional $account parameter is passed, then the array is filtered to values settable by the account.

Parameters

AccountInterface $account

(optional) The user account for which to filter the settable values. If omitted, all settable values are returned.

Return Value

array

An array of settable values.

array getSettableOptions(AccountInterface $account = NULL)

Returns an array of settable values with labels for display.

If the optional $account parameter is passed, then the array is filtered to values settable by the account.

Parameters

AccountInterface $account

(optional) The user account for which to filter the settable options. If omitted, all settable options are returned.

Return Value

array

An array of settable options for the object that may be used in an Options widget, usually when new data should be entered. It may either be a flat array of option labels keyed by values, or a two-dimensional array of option groups (array of flat option arrays, keyed by option group label). Note that labels should NOT be sanitized.

static fieldSettingsAjaxProcess($form, FormStateInterface $form_state)

Render API callback: Processes the field settings form.

Allows access to the form state.

Parameters

$form
FormStateInterface $form_state

See also

\Drupal\Core\Field\Plugin\Field\FieldType\static::fieldSettingsForm()

static fieldSettingsAjaxProcessElement($element, $main_form)

Adds entity_reference specific properties to AJAX form elements from the field settings form.

Parameters

$element
$main_form

See also

\Drupal\Core\Field\Plugin\Field\FieldType\static::fieldSettingsAjaxProcess()

static formProcessMergeParent($element)

Render API callback: Moves entity_reference specific Form API elements (i.e. 'handler_settings') up a level for easier processing by the validation and submission handlers.

Parameters

$element

See also

_entity_reference_field_settings_process()

static settingsAjax($form, FormStateInterface $form_state)

Ajax callback for the handler settings form.

Parameters

$form
FormStateInterface $form_state

See also

\Drupal\Core\Field\Plugin\Field\FieldType\static::fieldSettingsForm()

static settingsAjaxSubmit($form, FormStateInterface $form_state)

Submit handler for the non-JS case.

Parameters

$form
FormStateInterface $form_state

See also

\Drupal\Core\Field\Plugin\Field\FieldType\static::fieldSettingsForm()

static array[] getPreconfiguredOptions()

Returns preconfigured field options for a field type.

Note that if you want to give modules an opportunity to alter the result of this method, you should call \Drupal\Core\Field\FieldTypePluginManagerInterface::getPreconfiguredOptions() instead.

Return Value

array[]

A multi-dimensional array with string keys and the following structure:

  • label: The label to show in the field type selection list.
  • category: (optional) The category in which to put the field label. Defaults to the category of the field type.
  • field_storage_config: An array with the following supported keys:
    • cardinality: The field cardinality.
    • settings: Field-type specific storage settings.
  • field_config: An array with the following supported keys:
    • required: Indicates whether the field is required.
    • settings: Field-type specific settings.
  • entity_form_display: An array with the following supported keys:
    • type: The widget to be used in the 'default' form mode.
  • entity_view_display: An array with the following supported keys:
    • type: The formatter to be used in the 'default' view mode.

static validateDirectory($element, FormStateInterface $form_state)

Form API callback.

Removes slashes from the beginning and end of the destination value and ensures that the file directory path is not included at the beginning of the value.

This function is assigned as an #element_validate callback in fieldSettingsForm().

Parameters

$element
FormStateInterface $form_state

static validateExtensions($element, FormStateInterface $form_state)

Form API callback.

This function is assigned as an #element_validate callback in fieldSettingsForm().

This doubles as a convenience clean-up function and a validation routine. Commas are allowed by the end-user, but ultimately the value will be stored as a space-separated list for compatibility with file_validate_extensions().

Parameters

$element
FormStateInterface $form_state

static validateMaxFilesize($element, FormStateInterface $form_state)

Form API callback.

Ensures that a size has been entered and that it can be parsed by \Drupal\Component\Utility\Bytes::toNumber().

This function is assigned as an #element_validate callback in fieldSettingsForm().

Parameters

$element
FormStateInterface $form_state

string getUploadLocation(array $data = [])

Determines the URI for a file field.

Parameters

array $data

An array of token objects to pass to Token::replace().

Return Value

string

An unsanitized file directory URI with tokens replaced. The result of the token replacement is then converted to plain text and returned.

See also

Token::replace

static protected string doGetUploadLocation(array $settings, array $data = [])

Determines the URI for a file field.

Parameters

array $settings

The array of field settings.

array $data

An array of token objects to pass to Token::replace().

Return Value

string

An unsanitized file directory URI with tokens replaced. The result of the token replacement is then converted to plain text and returned.

See also

Token::replace

array getUploadValidators()

Retrieves the upload validators for a file field.

Return Value

array

An array suitable for passing to file_save_upload() or the file field element's '#upload_validators' property.

bool isDisplayed()

Determines whether an item should be displayed when rendering the field.

Return Value

bool

TRUE if the item should be displayed, FALSE if not.