function field_default_insert
7.x field.default.inc | 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.
2 invocations of field_default_insert()
- field_attach_insert in drupal-7.x/
modules/ field/ field.attach.inc - Save field data for a new entity.
- user_save in drupal-7.x/
modules/ user/ user.module - Save changes to a user account or add a new user.
File
- drupal-7.x/
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);
}
}