function EntityTestDefaultValue::descriptionDefaultValue

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

File

core/modules/system/tests/modules/entity_test/src/Entity/EntityTestDefaultValue.php, line 57

Class

EntityTestDefaultValue
Defines a test entity class for testing default values.

Namespace

Drupal\entity_test\Entity

Code

public static function descriptionDefaultValue(FieldableEntityInterface $entity, FieldDefinitionInterface $definition) : array {
    // 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.