Drupal 8  8.0.2
FieldItemBase Class Reference
Inheritance diagram for FieldItemBase:

Public Member Functions

 __construct (DataDefinitionInterface $definition, $name=NULL, TypedDataInterface $parent=NULL)
 
 getEntity ()
 
 getLangcode ()
 
 getFieldDefinition ()
 
 setValue ($values, $notify=TRUE)
 
 __get ($name)
 
 __set ($name, $value)
 
 __isset ($name)
 
 __unset ($name)
 
 view ($display_options=array())
 
 preSave ()
 
 postSave ($update)
 
 delete ()
 
 deleteRevision ()
 
 storageSettingsForm (array &$form, FormStateInterface $form_state, $has_data)
 
 fieldSettingsForm (array $form, FormStateInterface $form_state)
 
- Public Member Functions inherited from Map
 getValue ()
 
 setValue ($values, $notify=TRUE)
 
 getString ()
 
 get ($property_name)
 
 set ($property_name, $value, $notify=TRUE)
 
 getProperties ($include_computed=FALSE)
 
 toArray ()
 
 getIterator ()
 
 isEmpty ()
 
 __clone ()
 
 onChange ($property_name, $notify=TRUE)
 
 applyDefaultValue ($notify=TRUE)
 
- Public Member Functions inherited from TypedData
 __construct ($definition, $name=NULL, TypedDataInterface $parent=NULL)
 
 getPluginId ()
 
 getPluginDefinition ()
 
 getDataDefinition ()
 
 getValue ()
 
 setValue ($value, $notify=TRUE)
 
 getString ()
 
 getConstraints ()
 
 validate ()
 
 applyDefaultValue ($notify=TRUE)
 
 setContext ($name=NULL, TraversableTypedDataInterface $parent=NULL)
 
 getName ()
 
 getRoot ()
 
 getPropertyPath ()
 
 getParent ()
 
- Public Member Functions inherited from TraversableTypedDataInterface
 onChange ($name)
 

Static Public Member Functions

static defaultStorageSettings ()
 
static defaultFieldSettings ()
 
static mainPropertyName ()
 
static generateSampleValue (FieldDefinitionInterface $field_definition)
 
static storageSettingsToConfigData (array $settings)
 
static storageSettingsFromConfigData (array $settings)
 
static fieldSettingsToConfigData (array $settings)
 
static fieldSettingsFromConfigData (array $settings)
 
static calculateDependencies (FieldDefinitionInterface $field_definition)
 
static calculateStorageDependencies (FieldStorageDefinitionInterface $field_definition)
 
static onDependencyRemoval (FieldDefinitionInterface $field_definition, array $dependencies)
 
- Static Public Member Functions inherited from TypedData
static createInstance ($definition, $name=NULL, TraversableTypedDataInterface $parent=NULL)
 
- Static Public Member Functions inherited from FieldItemInterface
static propertyDefinitions (FieldStorageDefinitionInterface $field_definition)
 
static schema (FieldStorageDefinitionInterface $field_definition)
 

Protected Member Functions

 getSettings ()
 
 getSetting ($setting_name)
 
 writePropertyValue ($property_name, $value)
 
- Protected Member Functions inherited from Map
 writePropertyValue ($property_name, $value)
 

Additional Inherited Members

- Protected Attributes inherited from Map
 $definition
 
 $values = array()
 
 $properties = array()
 
- Protected Attributes inherited from TypedData
 $definition
 
 $name
 
 $parent
 

Detailed Description

An entity field item.

Entity field items making use of this base class have to implement the static method propertyDefinitions().

See Also

Constructor & Destructor Documentation

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

{}

References DataDefinitionInterface\isComputed(), and Drupal\typedDataManager().

Here is the call graph for this function:

Member Function Documentation

__get (   $name)

{Magic method: Gets a property value.

Parameters
$property_nameThe name of the property to get; e.g., 'title' or 'name'.
Returns
The property object.
Exceptions
\InvalidArgumentExceptionIf a not existing property is accessed.
}

Implements FieldItemInterface.

__isset (   $name)

{Magic method: Determines whether a property is set.

Parameters
$property_nameThe name of the property to get; e.g., 'title' or 'name'.
Returns
bool Returns TRUE if the property exists and is set, FALSE otherwise.
}

Implements FieldItemInterface.

__set (   $name,
  $value 
)

{Magic method: Sets a property value.

Parameters
$property_nameThe name of the property to set; e.g., 'title' or 'name'.
$valueThe value to set, or NULL to unset the property. Optionally, a typed data object implementing Drupal may be passed instead of a plain value.
Exceptions
\InvalidArgumentExceptionIf a not existing property is set.
}

Implements FieldItemInterface.

References Map\set().

Here is the call graph for this function:

__unset (   $name)

{Magic method: Unsets a property.

Parameters
$property_nameThe name of the property to get; e.g., 'title' or 'name'.
}

Implements FieldItemInterface.

References Map\set().

Here is the call graph for this function:

static calculateDependencies ( FieldDefinitionInterface  $field_definition)
static

{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
\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe field definition.
Returns
array An array of dependencies grouped by type (config, content, module, theme). For example:
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'),
);
See Also
::getConfigDependencyName()
}

Implements FieldItemInterface.

static calculateStorageDependencies ( FieldStorageDefinitionInterface  $field_definition)
static

{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
\Drupal\Core\Field\FieldStorageDefinitionInterface$field_storage_definitionThe field storage definition.
Returns
array An array of dependencies grouped by type (config, content, module, theme). For example:
[
'config' => ['user.role.anonymous', 'user.role.authenticated'],
'content' => ['node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'],
'module' => ['node', 'user'],
'theme' => ['seven'],
];
See Also
::getConfigDependencyName()
}

Implements FieldItemInterface.

static defaultFieldSettings ( )
static

{Defines the field-level settings for this plugin.

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

Implements FieldItemInterface.

static defaultStorageSettings ( )
static

{Defines the storage-level settings for this plugin.

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

Implements FieldItemInterface.

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.}

Implements FieldItemInterface.

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.}

Implements FieldItemInterface.

fieldSettingsForm ( array  $form,
FormStateInterface  $form_state 
)

{Returns a form for the field-level settings.Invoked from to allow administrators to configure field-level settings.

Parameters
array$formThe form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state of the (entire) configuration form.
Returns
array The form definition for the field settings.
}

Implements FieldItemInterface.

static fieldSettingsFromConfigData ( array  $settings)
static

{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$settingsThe field's settings, as it is stored within a configuration object.
Returns
array The field settings, in the representation expected by the field type and code that interacts with it.
See Also
::fieldSettingsToConfigData()
}

Implements FieldItemInterface.

static fieldSettingsToConfigData ( array  $settings)
static

{Returns a settings array that can be stored as a configuration value.Same as static::storageSettingsToConfigData(), but for the field's settings.

Parameters
array$settingsThe field's settings in the field type's canonical representation.
Returns
array An array (either the unmodified $settings or a modified representation) that is suitable for storing as a deployable configuration value.
See Also
::storageSettingsToConfigData()
}

Implements FieldItemInterface.

static generateSampleValue ( FieldDefinitionInterface  $field_definition)
static

{Generates placeholder field values.Useful when populating site with placeholder content during site building or profiling.

Parameters
\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe field definition.
Returns
array An associative array of values.
}

Implements FieldItemInterface.

getEntity ( )

{Gets the entity that field belongs to.

Returns
The entity object.
}

Implements FieldItemInterface.

References TypedData\getParent().

Referenced by DefaultLanguageItem\applyDefaultValue(), PathItem\delete(), TestItem\delete(), ListItemBase\getSettableOptions(), EntityReferenceItem\getSettableOptions(), UserNameItem\isEmpty(), PathItem\postSave(), FieldTestItem\postSave(), PasswordItem\preSave(), FieldTestItem\preSave(), ListItemBase\storageSettingsForm(), CommentItem\storageSettingsForm(), and FieldItemBase\view().

Here is the call graph for this function:

Here is the caller graph for this function:

getLangcode ( )

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

Returns
$langcode The langcode.
}

Implements FieldItemInterface.

Referenced by PathItem\postSave().

Here is the caller graph for this function:

getSetting (   $setting_name)
protected

Returns the value of a field setting.

Parameters
string$setting_nameThe setting name.
Returns
mixed The setting value.

References FieldItemBase\getFieldDefinition().

Referenced by BooleanItem\fieldSettingsForm(), LinkItem\fieldSettingsForm(), TestItem\fieldSettingsForm(), EntityReferenceItem\fieldSettingsForm(), StringItem\getConstraints(), TextItem\getConstraints(), IntegerItem\getConstraints(), BooleanItem\getPossibleOptions(), FileItem\isDisplayed(), DecimalItem\preSave(), TextItem\storageSettingsForm(), TestItem\storageSettingsForm(), StringItem\storageSettingsForm(), DateTimeItem\storageSettingsForm(), ListItemBase\storageSettingsForm(), FileItem\storageSettingsForm(), CommentItem\storageSettingsForm(), and EntityReferenceItem\storageSettingsForm().

Here is the call graph for this function:

Here is the caller graph for this function:

getSettings ( )
protected

Returns the array of field settings.

Returns
array The array of settings.

References FieldItemBase\getFieldDefinition().

Referenced by NumericItemBase\fieldSettingsForm(), TextWithSummaryItem\fieldSettingsForm(), CommentItem\fieldSettingsForm(), DecimalItem\fieldSettingsForm(), FileItem\fieldSettingsForm(), ImageItem\fieldSettingsForm(), NumericItemBase\getConstraints(), FileItem\getUploadLocation(), FileItem\getUploadValidators(), and DecimalItem\storageSettingsForm().

Here is the call graph for this function:

Here is the caller graph for this function:

static mainPropertyName ( )
static

{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.

Returns
string|null The name of the value property, or NULL if there is none.
See Also
}

Implements FieldItemInterface.

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

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

Parameters
\Drupal\Core\Field\FieldDefinitionInterface$field_definitionThe field definition.
array$dependenciesAn array of dependencies that will be deleted keyed by dependency type. Dependency types are, for example, entity, module and theme.
Returns
bool TRUE if the field definition has been changed as a result, FALSE if not.
See Also
::onDependencyRemoval()
}

Implements FieldItemInterface.

postSave (   $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$updateSpecifies whether the entity is being updated or created.
Returns
bool Whether field items should be rewritten to the storage as a consequence of the logic implemented by the custom behavior.
}

Implements FieldItemInterface.

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.}

Implements FieldItemInterface.

setValue (   $values,
  $notify = TRUE 
)

{Sets the data value.

Parameters
mixed | null$valueThe value to set in the format as documented for the data type or NULL to unset the data value.
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.
Exceptions
\InvalidArgumentExceptionIf the value input is inappropriate.
\Drupal\Core\TypedData\Exception\ReadOnlyExceptionIf the data is read-only.
}

Implements TypedDataInterface.

Referenced by CreatedItem\applyDefaultValue(), UuidItem\applyDefaultValue(), TextItemBase\applyDefaultValue(), FieldTestItem\postSave(), and FieldTestItem\preSave().

Here is the caller graph for this function:

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

{Returns a form for the storage-level settings.Invoked from 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$formThe form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface$form_stateThe form state of the (entire) configuration form.
bool$has_dataTRUE if the field already has data, FALSE if not.
Returns
The form definition for the field settings.
}

Implements FieldItemInterface.

static storageSettingsFromConfigData ( array  $settings)
static

{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$settingsThe field's settings, as it is stored within a configuration object.
Returns
array The settings, in the representation expected by the field type and code that interacts with it.
See Also
::storageSettingsToConfigData()
}

Implements FieldItemInterface.

static storageSettingsToConfigData ( array  $settings)
static

{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 ::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$settingsThe field's settings in the field type's canonical representation.
Returns
array An array (either the unmodified $settings or a modified representation) that is suitable for storing as a deployable configuration value.
See Also
::set()
}

Implements FieldItemInterface.

view (   $display_options = array())

{Returns a renderable array for a single field item.

Parameters
array$display_optionsCan be either the name of a view mode, or an array of display settings. See EntityViewBuilderInterface::viewField() for more information.
Returns
array A renderable array for the field item.
See Also
::viewField()
::viewFieldItem()
::view()
}

Implements FieldItemInterface.

References Drupal\entityManager(), and FieldItemBase\getEntity().

Here is the call graph for this function:

writePropertyValue (   $property_name,
  $value 
)
protected

{}

Different to the parent Map class, we avoid creating property objects as far as possible in order to optimize performance. Thus we just update $this->values if no property object has been created yet.

Referenced by TextItemBase\onChange(), LanguageItem\onChange(), and EntityReferenceItem\onChange().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: