function field_default_insert
field_default_insert($entity_type, $entity, $field, $instance, $langcode, &$items)
Default field 'insert' operation.
Insert default value if no $entity->$field_name entry was provided. This can happen with programmatic saves, or on form-based creation where the current user doesn't have 'edit' permission for the field.
File
- modules/field/field.default.inc, line 103
- Default 'implementations' of hook_field_*(): common field housekeeping.
Code
function field_default_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { // _field_invoke() populates $items with an empty array if the $entity has no // entry for the field, so we check on the $entity itself. // We also check that the current field translation is actually defined before // assigning it a default value. This way we ensure that only the intended // languages get a default value. Otherwise we could have default values for // not yet open languages. if (empty($entity) || !property_exists($entity, $field['field_name']) || (isset($entity->{$field['field_name']}[$langcode]) && count($entity->{$field['field_name']}[$langcode]) == 0)) { $items = field_get_default_value($entity_type, $entity, $field, $instance, $langcode); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!field!field.default.inc/function/field_default_insert/7.x