function field_get_default_value

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

Parameters

$entity_type: The type of $entity; e.g., 'node' or 'user'.

$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

2 calls to field_get_default_value()
field_default_insert in drupal/core/modules/field/field.default.inc
Inserts a default value if no $entity->$field_name entry was provided.
WidgetBase::form in drupal/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php
Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::form().

File

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

Code

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