You are here

protected property FieldConfigBase::$default_value in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::default_value

Default field value.

The default value is used when an entity is created, either:

  • through an entity creation form; the form elements for the field are prepopulated with the default value.
  • through direct API calls (i.e. $entity->save()); the default value is added if the $entity object provides no explicit entry (actual values or "the field is empty") for the field.

The default value is expressed as a numerically indexed array of items, each item being an array of key/value pairs matching the set of 'columns' defined by the "field schema" for the field type, as exposed in the class implementing \Drupal\Core\Field\FieldItemInterface::schema() method. If the number of items exceeds the cardinality of the field, extraneous items will be ignored.

This property is overlooked if the $default_value_callback is non-empty.

Example for an integer field:

array(
  array(
    'value' => 1,
  ),
  array(
    'value' => 2,
  ),
);

Type: array

File

core/lib/Drupal/Core/Field/FieldConfigBase.php, line 145

Class

FieldConfigBase
Base class for configurable field definitions.

Namespace

Drupal\Core\Field

Code

protected $default_value = [];