Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_field_default_value()
  2. 9 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_field_default_value()

Field default value callback.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity being created.

\Drupal\Core\Field\FieldDefinitionInterface $definition: The field definition.

Return value

array An array of default values, in the same format as the $default_value property.

See also

\Drupal\field\Entity\FieldConfig::$default_value

2 string references to 'entity_test_field_default_value'
EntityTestDefaultValue::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php
Provides base field definitions for an entity type.
EntityTestMulDefaultValue::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php
Provides base field definitions for an entity type.

File

core/modules/system/tests/modules/entity_test/entity_test.module, line 664
Test module for the entity API providing several entity types for testing.

Code

function entity_test_field_default_value(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {

  // Include the field name and entity language in the generated values to check
  // that they are correctly passed.
  $string = $definition
    ->getName() . '_' . $entity
    ->language()
    ->getId();

  // Return a "default value" with multiple items.
  return [
    [
      'shape' => "shape:0:{$string}",
      'color' => "color:0:{$string}",
    ],
    [
      'shape' => "shape:1:{$string}",
      'color' => "color:1:{$string}",
    ],
  ];
}