function entity_test_field_default_value

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_field_default_value()
  2. 8.9.x core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_field_default_value()
  3. 10 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
EntityTestMulDefaultValue::baseFieldDefinitions in core/modules/system/tests/modules/entity_test/src/Entity/EntityTestMulDefaultValue.php

File

core/modules/system/tests/modules/entity_test/entity_test.module, line 664

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}",
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.