Drupal 8  8.0.2
EntityReferenceItem Class Reference
Inheritance diagram for EntityReferenceItem:

Public Member Functions

 getConstraints ()
 
 setValue ($values, $notify=TRUE)
 
 getValue ()
 
 onChange ($property_name, $notify=TRUE)
 
 isEmpty ()
 
 preSave ()
 
 storageSettingsForm (array &$form, FormStateInterface $form_state, $has_data)
 
 fieldSettingsForm (array $form, FormStateInterface $form_state)
 
 hasNewEntity ()
 
 getPossibleValues (AccountInterface $account=NULL)
 
 getPossibleOptions (AccountInterface $account=NULL)
 
 getSettableValues (AccountInterface $account=NULL)
 
 getSettableOptions (AccountInterface $account=NULL)
 
- Public Member Functions inherited from FieldItemBase
 __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 propertyDefinitions (FieldStorageDefinitionInterface $field_definition)
 
static mainPropertyName ()
 
static schema (FieldStorageDefinitionInterface $field_definition)
 
static generateSampleValue (FieldDefinitionInterface $field_definition)
 
static fieldSettingsFormValidate (array $form, FormStateInterface $form_state)
 
static calculateDependencies (FieldDefinitionInterface $field_definition)
 
static calculateStorageDependencies (FieldStorageDefinitionInterface $field_definition)
 
static onDependencyRemoval (FieldDefinitionInterface $field_definition, array $dependencies)
 
static fieldSettingsAjaxProcess ($form, FormStateInterface $form_state)
 
static fieldSettingsAjaxProcessElement (&$element, $main_form)
 
static formProcessMergeParent ($element)
 
static settingsAjax ($form, FormStateInterface $form_state)
 
static settingsAjaxSubmit ($form, FormStateInterface $form_state)
 
- Static Public Member Functions inherited from FieldItemBase
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 PreconfiguredFieldUiOptionsInterface
static getPreconfiguredOptions ()
 

Additional Inherited Members

- Protected Member Functions inherited from FieldItemBase
 getSettings ()
 
 getSetting ($setting_name)
 
 writePropertyValue ($property_name, $value)
 
- Protected Member Functions inherited from Map
 writePropertyValue ($property_name, $value)
 
- Protected Attributes inherited from Map
 $definition
 
 $values = array()
 
 $properties = array()
 
- Protected Attributes inherited from TypedData
 $definition
 
 $name
 
 $parent
 

Detailed Description

Defines the 'entity_reference' entity field type.

Supported settings (below the definition's 'settings' key) are:

  • target_type: The entity type to reference. Required.

( id = "entity_reference", label = ("Entity reference"), description = ("An entity field containing an entity reference."), category = ("Reference"), default_widget = "entity_reference_autocomplete", default_formatter = "entity_reference_label", list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList", )

Member Function Documentation

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.

References Drupal\entityManager(), FieldDefinitionInterface\getDefaultValueLiteral(), FieldDefinitionInterface\getFieldStorageDefinition(), and DataDefinitionInterface\getSetting().

Here is the call graph for this function:

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.

References Drupal\entityManager(), and FieldStorageDefinitionInterface\getSetting().

Here is the call graph for this function:

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.

References Drupal\moduleHandler().

Here is the call graph for this function:

static fieldSettingsAjaxProcess (   $form,
FormStateInterface  $form_state 
)
static

Render API callback: Processes the field settings form and allows access to the form state.

See Also
static::fieldSettingsForm()
static fieldSettingsAjaxProcessElement ( $element,
  $main_form 
)
static

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

See Also
static::fieldSettingsAjaxProcess()

References Element\children().

Here is the call graph for this function:

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.

References Html\escape(), FormStateInterface\getFormObject(), FieldItemBase\getSetting(), Drupal\service(), and t().

Here is the call graph for this function:

static fieldSettingsFormValidate ( array  $form,
FormStateInterface  $form_state 
)
static

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

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.

References FormStateInterface\getFormObject(), and Drupal\service().

Here is the call graph for this function:

static formProcessMergeParent (   $element)
static

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.

See Also
_entity_reference_field_settings_process()
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.

References Drupal\service().

Here is the call graph for this function:

getConstraints ( )

{Gets a list of validation constraints.

Returns
array Array of constraints, each being an instance of .
}

Implements TypedDataInterface.

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
\Drupal\Core\Session\AccountInterface$account(optional) The user account for which to filter the possible options. If omitted, all possible options are returned.
Returns
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.
}

Implements OptionsProviderInterface.

References EntityReferenceItem\getSettableOptions().

Here is the call graph for this function:

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
\Drupal\Core\Session\AccountInterface$account(optional) The user account for which to filter the possible values. If omitted, all possible values are returned.
Returns
array An array of possible values.
}

Implements OptionsProviderInterface.

References EntityReferenceItem\getSettableValues().

Here is the call graph for this function:

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
\Drupal\Core\Session\AccountInterface$account(optional) The user account for which to filter the settable options. If omitted, all settable options are returned.
Returns
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.
}

Implements OptionsProviderInterface.

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

Referenced by EntityReferenceItem\getPossibleOptions(), and EntityReferenceItem\getSettableValues().

Here is the call graph for this function:

Here is the caller graph for this function:

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
\Drupal\Core\Session\AccountInterface$account(optional) The user account for which to filter the settable values. If omitted, all settable values are returned.
Returns
array An array of settable values.
}

Implements OptionsProviderInterface.

References OptGroup\flattenOptions(), and EntityReferenceItem\getSettableOptions().

Referenced by EntityReferenceItem\getPossibleValues().

Here is the call graph for this function:

Here is the caller graph for this function:

getValue ( )

{Gets the data value.

Returns
mixed
}

Implements TypedDataInterface.

References EntityReferenceItem\hasNewEntity().

Here is the call graph for this function:

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

Returns
bool TRUE if the item holds an unsaved entity.

References EntityReferenceItem\isEmpty().

Referenced by EntityReferenceItem\getValue(), EntityReferenceFormatterBase\needsEntityLoad(), and EntityReferenceItem\preSave().

Here is the call graph for this function:

Here is the caller graph for this function:

isEmpty ( )

{Determines whether the data structure is empty.

Returns
bool TRUE if the data structure is empty, FALSE otherwise.
}

Implements ComplexDataInterface.

Referenced by EntityReferenceItem\hasNewEntity(), and EntityReferenceItem\preSave().

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.

onChange (   $property_name,
  $notify = TRUE 
)

{}

References FieldItemBase\writePropertyValue().

Referenced by EntityReferenceItem\setValue().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

References Drupal\entityManager(), FieldDefinitionInterface\getDefaultValueLiteral(), FieldDefinitionInterface\getFieldStorageDefinition(), FieldDefinitionInterface\getName(), DataDefinitionInterface\getSetting(), FieldDefinitionInterface\getTargetBundle(), FieldDefinitionInterface\getTargetEntityTypeId(), and Drupal\logger().

Here is the call graph for this function:

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.

References EntityReferenceItem\hasNewEntity(), and EntityReferenceItem\isEmpty().

Here is the call graph for this function:

static propertyDefinitions ( FieldStorageDefinitionInterface  $field_definition)
static

{Defines field item properties.Properties that are required to constitute a valid, non-empty item should be denoted with ::setRequired().

Returns
[] An array of property definitions of contained properties, keyed by property name.
See Also
}

Implements FieldItemInterface.

References EntityDataDefinition\create(), DataDefinition\create(), DataReferenceDefinition\create(), Drupal\entityManager(), and FieldStorageDefinitionInterface\getSettings().

Here is the call graph for this function:

static schema ( FieldStorageDefinitionInterface  $field_definition)
static

{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
\Drupal\Core\Field\FieldStorageDefinitionInterface$field_definitionThe field definition.
Returns
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}.
}

Implements FieldItemInterface.

References EntityTypeInterface\BUNDLE_MAX_LENGTH, Drupal\entityManager(), and FieldStorageDefinitionInterface\getSetting().

Referenced by EntityViewsDataTest\setupFieldStorageDefinition().

Here is the call graph for this function:

Here is the caller graph for this function:

static settingsAjax (   $form,
FormStateInterface  $form_state 
)
static

Ajax callback for the handler settings form.

See Also
static::fieldSettingsForm()

References FormStateInterface\getTriggeringElement(), and NestedArray\getValue().

Here is the call graph for this function:

static settingsAjaxSubmit (   $form,
FormStateInterface  $form_state 
)
static

Submit handler for the non-JS case.

See Also
static::fieldSettingsForm()

References FormStateInterface\setRebuild().

Here is the call graph for this function:

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.

References TypedData\getName(), EntityReferenceItem\onChange(), and Map\set().

Here is the call 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.

References Drupal\entityManager(), FieldItemBase\getSetting(), and t().

Here is the call graph for this function:


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