Drupal 8  8.0.2
FieldConfigBase Class Reference
Inheritance diagram for FieldConfigBase:

## Public Member Functions

id ()

getName ()

getType ()

getTargetEntityTypeId ()

getTargetBundle ()

onDependencyRemoval (array $dependencies) postCreate (EntityStorageInterface$storage)

postSave (EntityStorageInterface $storage,$update=TRUE)

getLabel ()

setLabel ($label) getDescription () setDescription ($description)

isTranslatable ()

setTranslatable ($translatable) getSettings () setSettings (array$settings)

getSetting ($setting_name) setSetting ($setting_name, $value) isRequired () setRequired ($required)

getDefaultValue (FieldableEntityInterface $entity) getDefaultValueLiteral () setDefaultValue ($value)

getDefaultValueCallback ()

setDefaultValueCallback ($callback) __sleep () getDataType () isList () getClass () getConstraints () getConstraint ($constraint_name)

getItemDefinition ()

getConfig ($bundle) setConstraints (array$constraints)

addConstraint ($constraint_name,$options=NULL)

setPropertyConstraints ($name, array$constraints)

addPropertyConstraints ($name, array$constraints)

Public Member Functions inherited from ConfigEntityBase
__construct (array $values,$entity_type)

getOriginalId ()

setOriginalId ($id) isNew () get ($property_name)

set ($property_name,$value)

enable ()

disable ()

setStatus ($status) status () setSyncing ($syncing)

isSyncing ()

setUninstalling ($uninstalling) isUninstalling () createDuplicate () preSave (EntityStorageInterface$storage)

calculateDependencies ()

urlInfo ($rel= 'edit-form', array$options=[])

url ($rel= 'edit-form',$options=array())

link ($text=NULL,$rel= 'edit-form', array $options=[]) toUrl ($rel= 'edit-form', array $options=[]) getCacheTagsToInvalidate () getDependencies () getConfigDependencyName () getConfigTarget () onDependencyRemoval (array$dependencies)

setThirdPartySetting ($module,$key, $value) getThirdPartySetting ($module, $key,$default=NULL)

getThirdPartySettings ($module) unsetThirdPartySetting ($module, $key) getThirdPartyProviders () isInstallable () trustData () hasTrustedData () save () Public Member Functions inherited from Entity __construct (array$values, $entity_type) id () uuid () isNew () enforceIsNew ($value=TRUE)

getEntityTypeId ()

bundle ()

label ()

urlInfo ($rel= 'canonical', array$options=[])

toUrl ($rel= 'canonical', array$options=[])

hasLinkTemplate ($rel) link ($text=NULL, $rel= 'canonical', array$options=[])

toLink ($text=NULL,$rel= 'canonical', array $options=[]) url ($rel= 'canonical', $options=array()) uriRelationships () access ($operation, AccountInterface $account=NULL,$return_as_object=FALSE)

language ()

save ()

delete ()

createDuplicate ()

getEntityType ()

preSave (EntityStorageInterface $storage) postSave (EntityStorageInterface$storage, $update=TRUE) postCreate (EntityStorageInterface$storage)

referencedEntities ()

getCacheContexts ()

getCacheTagsToInvalidate ()

getCacheTags ()

getCacheMaxAge ()

getOriginalId ()

setOriginalId ($id) toArray () getTypedData () __sleep () getConfigDependencyKey () getConfigDependencyName () getConfigTarget () Public Member Functions inherited from RefinableCacheableDependencyInterface addCacheContexts (array$cache_contexts)

addCacheTags (array $cache_tags) mergeCacheMaxAge ($max_age)

addCacheableDependency ($other_object) Public Member Functions inherited from FieldDefinitionInterface isDisplayConfigurable ($display_context)

getDisplayOptions ($display_context) getFieldStorageDefinition () Public Member Functions inherited from DataDefinitionInterface isReadOnly () isComputed () ## Static Public Member Functions static createFromItemType ($item_type)

static createFromDataType ($type) Static Public Member Functions inherited from ConfigEntityBase static sort (ConfigEntityInterface$a, ConfigEntityInterface $b) Static Public Member Functions inherited from Entity static preCreate (EntityStorageInterface$storage, array &$values) static preDelete (EntityStorageInterface$storage, array $entities) static postDelete (EntityStorageInterface$storage, array $entities) static postLoad (EntityStorageInterface$storage, array &$entities) static load ($id)

static loadMultiple (array $ids=NULL) static create (array$values=array())

## Protected Attributes

$id$field_name

$field_type$entity_type

$bundle$label

$description = ''$settings = array()

$required = FALSE$translatable = TRUE

$default_value = array()$default_value_callback = ''

$fieldStorage$itemDefinition

$constraints = [] Protected Attributes inherited from ConfigEntityBase$originalId

$pluginConfigKey$status = TRUE

$uuid$langcode = 'en'

$third_party_settings = array()$_core = []

$trustedData = FALSE Protected Attributes inherited from Entity$entityTypeId

$enforceIsNew$typedData

Protected Member Functions inherited from ConfigEntityBase
getTypedConfig ()

addDependency ($type,$name)

invalidateTagsOnSave ($update) Protected Member Functions inherited from Entity entityManager () entityTypeManager () languageManager () uuidGenerator () linkTemplates () urlRouteParameters ($rel)

invalidateTagsOnSave ($update) Static Protected Member Functions inherited from ConfigEntityBase static invalidateTagsOnDelete (EntityTypeInterface$entity_type, array $entities) static getConfigManager () Static Protected Member Functions inherited from Entity static invalidateTagsOnDelete (EntityTypeInterface$entity_type, array $entities) ## Detailed Description Base class for configurable field definitions. ## Member Function Documentation  __sleep ( ) Implements the magic __sleep() method. Using the Serialize interface and serialize() / unserialize() methods breaks entity forms in PHP 5.4. Todo: Investigate in https://www.drupal.org/node/2074253.  addConstraint ($constraint_name, $options = NULL ) {Adds a validation constraint to the FieldItemList.Note: If you wish to apply a constraint to just a property of a FieldItem use ::addPropertyConstraints() instead. // Add a constraint to the 'field_username' FieldItemList. // e.g.$node->field_username
$fields['field_username']->addConstraint('UniqueField'); If you wish to apply a constraint to a instead of a property or FieldItemList, you can use the ::getItemDefinition() method. // Add a constraint to the 'field_entity_reference' FieldItem (entity // reference item).$fields['field_entity_reference']->getItemDefinition()->addConstraint('MyCustomFieldItemValidationPlugin', []);
See ::getConstraints() for details.Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().
Parameters
 string $constraint_name The name of the constraint to add, i.e. its plugin id. array | null$options The constraint options as required by the constraint plugin, or NULL.
Returns
static The object itself for chaining.
hook_entity_bundle_field_info_alter()
}

Implements FieldConfigInterface.

 addPropertyConstraints ( $name, array$constraints )

{Adds constraints for a given field item property.Adds a constraint to a property of a field item. e.g.

// Limit the field item's value property to the range 0 through 10.
// e.g. $node->field_how_many->value.$field->addPropertyConstraints('value', [
'Range' => [
'min' => 0,
'max' => 10,
]
]);
If you want to add a validation constraint that applies to the , use FieldConfigInterface::addConstraint() instead.Note: passing a new set of options for an existing property constraint will overwrite with the new options.Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().
Parameters
 string $name The name of the property to set constraints for. array$constraints The constraints to set.
Returns
static The object itself for chaining.
hook_entity_bundle_field_info_alter()
}

Implements FieldConfigInterface.

References FieldConfigBase\getItemDefinition().

Here is the call graph for this function:

 static createFromDataType ( $type ) static {Creates a new data definition object.This method is typically used by ::createDataDefinition() to build a definition object for an arbitrary data type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.: Parameters  string$data_type The data type, for which a data definition should be created.
Returns
static
Exceptions
 \InvalidArgumentException If an unsupported data type gets passed to the class; e.g., 'string' to a definition class handling 'entity:* data types.
}

Here is the call graph for this function:

 static createFromItemType ( $item_type ) static {Creates a new list data definition for items of the given data type.This method is typically used by ::createListDataDefinition() to build a definition object for an arbitrary item type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.: Parameters  string$item_type The item type, for which a list data definition should be created.
Returns
static
Exceptions
 \InvalidArgumentException If an unsupported data type gets passed to the class; e.g., 'string' to a definition class handling lists of 'field_item:* data types.
}

References BaseFieldDefinition\createFromItemType().

Here is the call graph for this function:

 getClass ( )

{Returns the class used for creating the typed data object.If not specified, the default class of the data type will be returned.

Returns
string The class used for creating the typed data object.
}

References FieldConfigBase\getType(), and Drupal\service().

Referenced by FieldConfigBase\getDefaultValue().

Here is the call graph for this function:

Here is the caller graph for this function:

 getConfig ( $bundle ) {Gets an object that can be saved in configuration.Base fields are defined in code. In order to configure field definition properties per bundle use this method to create an override that can be saved in configuration. See Also Parameters  string$bundle The bundle to get the configurable field for.
Returns
}

Implements FieldDefinitionInterface.

 getConstraint ( $constraint_name ) {Returns a validation constraint.See ::getConstraints() for details. Parameters  string$constraint_name The name of the constraint, i.e. its plugin id.
Returns
array A validation constraint definition which can be used for instantiating a object.
}

References FieldConfigBase\getConstraints().

Here is the call graph for this function:

 getConstraints ( )

{Returns an array of validation constraints.The validation constraints of a definition consist of any for it defined constraints and default constraints, which are generated based on the definition and its data type. See ::getDefaultConstraints().Constraints are defined via an array, having constraint plugin IDs as key and constraint options as values, e.g.

$constraints = array( 'Range' => array('min' => 5, 'max' => 10), 'NotBlank' => array(), ); Options have to be specified using another array if the constraint has more than one or zero options. If it has exactly one option, the value should be specified without nesting it into another array:$constraints = array(
'EntityType' => 'node',
'Bundle' => 'article',
);
Note that the specified constraints must be compatible with the data type, e.g. for data of type 'entity' the 'EntityType' and 'Bundle' constraints may be specified.
Returns
array[] An array of validation constraint definitions, keyed by constraint name. Each constraint definition can be used for instantiating objects.
}

Referenced by FieldConfigBase\getConstraint().

Here is the caller graph for this function:

 getDataType ( )

{Returns the data type of the data.

Returns
string The data type.
}

 getDefaultValue ( FieldableEntityInterface $entity ) {Returns the default value for the field in a newly created entity.This method computes the runtime default value for a field in a given entity. To access the raw properties assigned to the field definition, ::getDefaultValueLiteral() or ::getDefaultValueCallback() should be used instead. Parameters  \Drupal\Core\Entity\FieldableEntityInterface$entity The entity for which the default value is generated.
Returns
array The default value for the field, as a numerically indexed array of items, each item being a property/value array (array() for no default value).
FieldDefinitionInterface::getDefaultValueLiteral()
FieldDefinitionInterface::getDefaultValueCallback()
}

Implements FieldDefinitionInterface.

Here is the call graph for this function:

 getDefaultValueCallback ( )

{Returns the default value callback for the field.This method retrieves the raw property assigned to the field definition. When computing the runtime default value for a field in a given entity, ::getDefaultValue() should be used instead.

Returns
string|null The default value callback for the field.
FieldDefinitionInterface::getDefaultValue()
FieldDefinitionInterface::getDefaultValueLiteral()
}

Implements FieldDefinitionInterface.

Referenced by FieldConfigBase\getDefaultValue().

Here is the caller graph for this function:

 getDefaultValueLiteral ( )

{Returns the default value literal for the field.This method retrieves the raw property assigned to the field definition. When computing the runtime default value for a field in a given entity, ::getDefaultValue() should be used instead.

Returns
array The default value for the field, as a numerically indexed array of items, each item being a property/value array (array() for no default value).
FieldDefinitionInterface::getDefaultValue()
FieldDefinitionInterface::getDefaultValueCallback()
}

Implements FieldDefinitionInterface.

Referenced by FieldConfigBase\getDefaultValue().

Here is the caller graph for this function:

 getDescription ( )

{Returns a human readable description.Descriptions are usually used on user interfaces where the data is edited or displayed.

Returns
string|null The description, or NULL if no description is available.
}

 getItemDefinition ( )

{Gets the data definition of an item of the list.

Returns
A data definition describing the list items.
}

Here is the call graph for this function:

Here is the caller graph for this function:

 getLabel ( )

Returns
string| The label. A string or an instance of TranslatableMarkup will be returned based on the way the label translation is handled.
}

References Entity\label().

Here is the call graph for this function:

 getName ( )

{Returns the machine name of the field.This defines how the field data is accessed from the entity. For example, if the field name is "foo", then $entity->foo returns its data. Returns string The field name. } Implements FieldDefinitionInterface. Referenced by BaseFieldOverride\getBaseFieldDefinition(), and FieldConfig\postCreate(). Here is the caller graph for this function:  getSetting ($setting_name )

{Returns the value of a given setting.

Parameters
 string $setting_name The setting name. Returns mixed The setting value. } Implements DataDefinitionInterface. Here is the call graph for this function:  getSettings ( ) {Returns the array of settings, as required by the used class.See the documentation of the class for supported or required settings. Returns array The array of settings. } Implements DataDefinitionInterface. Referenced by FieldConfigBase\getItemDefinition(). Here is the call graph for this function: Here is the caller graph for this function:  getTargetBundle ( ) {Gets the bundle the field is attached to.This method should not be confused with EntityInterface::bundle() (configurable fields are config entities, and thus implement both interfaces): Returns string|null The bundle the field is defined for, or NULL if it is a base field; i.e., it is not bundle-specific. } Implements FieldDefinitionInterface.  getTargetEntityTypeId ( ) {Returns the ID of the entity type the field is attached to.This method should not be confused with EntityInterface::getEntityTypeId() (configurable fields are config entities, and thus implement both interfaces): Returns string The entity type ID. } Implements FieldDefinitionInterface. Referenced by BaseFieldOverride\preSave(). Here is the caller graph for this function:  getType ( ) {Returns the field type. Returns string The field type, i.e. the id of a field type plugin. For example 'text'. See Also } Implements FieldDefinitionInterface. Here is the caller graph for this function:  id ( ) {Gets the identifier. Returns string|int|null The entity identifier, or NULL if the object does not yet have an identifier. } Implements EntityInterface. References Entity\bundle(). Here is the call graph for this function:  isList ( ) {Returns whether the data is multi-valued, i.e. a list of data items.This is equivalent to checking whether the data definition implements the interface. Returns bool Whether the data is multi-valued. } Implements DataDefinitionInterface.  isRequired ( ) {Returns whether the field can be empty.If a field is required, an entity needs to have at least a valid, non-empty item in that field's FieldItemList in order to pass validation.An item is considered empty if its isEmpty() method returns TRUE. Typically, that is if at least one of its required properties is empty. Returns bool TRUE if the field is required. See Also ::isEmpty() ::isEmpty() :isRequired() ::getDefaultConstraints() } Implements FieldDefinitionInterface.  isTranslatable ( ) {Returns whether the field is translatable. Returns bool TRUE if the field is translatable. } Implements FieldDefinitionInterface. Here is the call graph for this function:  onDependencyRemoval ( array$dependencies )

{Informs the entity that entities it depends on will be deleted.This method allows configuration entities to remove dependencies instead of being deleted themselves. Configuration entities can use this method to avoid being unnecessarily deleted during an extension uninstallation. For example, entity displays remove references to widgets and formatters if the plugin that supplies them depends on a module that is being uninstalled.If this method returns TRUE then the entity needs to be re-saved by the caller for the changes to take effect. Implementations should not save the entity.

Parameters
 array $dependencies An 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 entity has changed, FALSE if not. bool TRUE if the entity has been changed as a result, FALSE if not. See Also ::preDelete() ::uninstall() ::onDependencyRemoval() } Implements ConfigEntityInterface. References FieldConfigBase\getType(), and Drupal\service(). Referenced by FieldConfigEntityUnitTest\testOnDependencyRemoval(). Here is the call graph for this function: Here is the caller graph for this function:  postCreate ( EntityStorageInterface$storage )

{Acts on an entity after it is created but before hooks are invoked.

Parameters
 \Drupal\Core\Entity\EntityStorageInterface $storage The entity storage object. } Implements EntityInterface. Here is the call graph for this function:  postSave ( EntityStorageInterface$storage, $update = TRUE ) {Acts on a saved entity before the insert or update hook is invoked.Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed. Parameters  \Drupal\Core\Entity\EntityStorageInterface$storage The entity storage object. bool $update TRUE if the entity has been updated, or FALSE if it has been inserted. } Implements EntityInterface. Here is the call graph for this function:  setConstraints ( array$constraints )

{Sets the array of validation constraints for the FieldItemList.NOTE: This will overwrite any previously set constraints. In most cases FieldConfigInterface::addConstraint() should be used instead.Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().

Parameters
 array $constraints The array of constraints. See ::getConstraints() for details. Returns$this
::getConstraints()
hook_entity_bundle_field_info_alter()
}

Implements FieldConfigInterface.

 setDefaultValue ( $value ) {Sets a default value.Note that if a default value callback is set, it will take precedence over any value set here. Parameters  mixed$value The default value for the field. This can be either: a literal, in which case it will be assigned to the first property of the first item. a numerically indexed array of items, each item being a property/value array. a non-numerically indexed array, in which case the array is assumed to be a property/value array and used as the first item NULL or array() for no default value.
Returns
$this } Implements FieldConfigInterface. Here is the call graph for this function:  setDefaultValueCallback ($callback )

{Sets a custom default value callback.If set, the callback overrides any set default value.

Parameters
 string | null $callback The callback to invoke for getting the default value (pass NULL to unset a previously set callback). The callback will be invoked with the following arguments:$entity The entity being created. $definition The field definition. It should return the default value in the format accepted by the setDefaultValue() method. Returns$this
}

Implements FieldConfigInterface.

 setDescription ( $description ) {Sets a human readable description.Descriptions are usually used on user interfaces where the data is edited or displayed. Parameters  string$description The description for this field.
Returns
$this } Implements FieldConfigInterface.  setLabel ($label )

{Sets the field definition label.

Parameters
 string $label The label to set. Returns$this
}

Implements FieldConfigInterface.

References Entity\label().

Here is the call graph for this function:

 setPropertyConstraints ( $name, array$constraints )

{Sets constraints for a given field item property.Note: this overwrites any existing property constraints. If you need to add to the existing constraints, use ::addPropertyConstraints()Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().

Parameters
 string $name The name of the property to set constraints for. array$constraints The constraints to set.
Returns
static The object itself for chaining.
hook_entity_bundle_field_info_alter()
}

Implements FieldConfigInterface.

References FieldConfigBase\getItemDefinition().

Here is the call graph for this function:

 setRequired ( $required ) [Sets whether the field can be empty.If a field is required, an entity needs to have at least a valid, non-empty item in that field's FieldItemList in order to pass validation.An item is considered empty if its isEmpty() method returns TRUE. Typically, that is if at least one of its required properties is empty. Parameters  bool$required TRUE if the field is required. FALSE otherwise.
Returns
$this The current object, for a fluent interface. } Implements FieldConfigInterface.  setSetting ($setting_name, $value ) {Sets the value for a field setting by name. Parameters  string$setting_name The name of the setting. mixed $value The value of the setting. Returns$this
}

Implements FieldConfigInterface.

 setSettings ( array $settings ) {Sets field settings.Note that the method does not unset existing settings not specified in the incoming$settings array.For example:

// Given these are the default settings.
$field_definition->getSettings() === [ 'fruit' => 'apple', 'season' => 'summer', ]; // Change only the 'fruit' setting.$field_definition->setSettings(['fruit' => 'banana']);
// The 'season' setting persists unchanged.
$field_definition->getSettings() === [ 'fruit' => 'banana', 'season' => 'summer', ]; For clarity, it is preferred to use setSetting() if not all available settings are supplied. Parameters  array$settings The array of field settings.
Returns
$this } Implements FieldConfigInterface.  setTranslatable ($translatable )

{Sets whether the field is translatable.

Parameters
 bool $translatable Whether the field is translatable. Returns$this
}

Implements FieldConfigInterface.

The documentation for this class was generated from the following file:
• d8/core/lib/Drupal/Core/Field/FieldConfigBase.php