field_get_default_value

  1. drupal
    1. 8
    2. 7
Versions
8 – 7 field_get_default_value($entity_type, $entity, $field, $instance, $langcode = NULL)

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 functions call field_get_default_value()

field_default_form in modules/field/field.form.inc
Create a separate form element for each field.
field_default_insert in modules/field/field.default.inc
Default field 'insert' operation.

Code

modules/field/field.module, line 490

<?php
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'];
    if (function_exists($function)) {
      $items = $function($entity_type, $entity, $field, $instance, $langcode);
    }
  }
  elseif (!empty($instance['default_value'])) {
    $items = $instance['default_value'];
  }
  return $items;
}
?>