function field_get_default_value

Helper function to get the default value for a field on an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for the operation.

$field: The field structure.

$instance: The instance structure.

$langcode: The field language to fill-in with the default value.

Related topics

1 call to field_get_default_value()
field_populate_default_values in drupal/core/modules/field/field.module
Inserts a default value for each entity field not having one.

File

drupal/core/modules/field/field.module, line 489
Attach custom data fields to Drupal entities.

Code

function field_get_default_value(EntityInterface $entity, $field, $instance, $langcode = NULL) {
  $items = array();
  if (!empty($instance['default_value_function'])) {
    $function = $instance['default_value_function'];
    $items = $function($entity, $field, $instance, $langcode);
  }
  elseif (!empty($instance['default_value'])) {
    $items = $instance['default_value'];
  }
  return $items;
}