7.x field.api.php hook_field_attach_presave($entity_type, $entity)

Act on field_attach_presave().

This hook is invoked after the field module has performed the operation.

See field_attach_presave() for details and arguments.

Related topics

1 invocation of hook_field_attach_presave()
field_attach_presave in modules/field/field.attach.inc
Perform necessary operations just before fields data get saved.


modules/field/field.api.php, line 1388
Hooks provided by the Field module.


function hook_field_attach_presave($entity_type, $entity) {

  // @todo Needs function body.


alanom’s picture

Happens before entity is saved.

hook_field_insert / hook_field_update are called after entity is saved.

iyerdevil’s picture

I have a situation where i have to attatch "_admin" to my book title that i save as a content type book (i Created it) , I created my module , where i did this using hook_update , But i want to do using _field_attach_presave or field_presave . My hook is not getting called , there is no notice or error..... Please Help.. Its very urgent....
i used this approach first .... NOT getting called
function current_posts_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {

echo "inside the function" ;
foreach ($items as $delta ) {

NancyDru’s picture

function mymodule_field_attach_presave($entity_type, $entity) {
  if ($entity_type == 'node' && $entity->type == 'mytype') {
    $fields = mymodule_reinit_fields();

    foreach ($fields as $field) {
      $value = field_get_items($entity_type, $entity, $field);
      if (empty($value)) {
        $info = field_info_instance($entity_type, $field, $entity->type);
        $entity->{$field} = array(LANGUAGE_NONE => $info['default_value']);
Johann Wagner’s picture

Whereas it works on fields when creating or updating nodes, it doesn't get called when you use field_attach_update().

Instead, you might use hook_field_storage_pre_update().