function filefield_paths_entity_update

cis7 filefield_paths.module filefield_paths_entity_update($entity, $type)
cle7 filefield_paths.module filefield_paths_entity_update($entity, $type)
elmsmedia7 filefield_paths.module filefield_paths_entity_update($entity, $type)
icor7 filefield_paths.module filefield_paths_entity_update($entity, $type)
meedjum_blog7 filefield_paths.module filefield_paths_entity_update($entity, $type)
mooc7 filefield_paths.module filefield_paths_entity_update($entity, $type)

Implements hook_entity_update().

2 calls to filefield_paths_entity_update()
filefield_paths_entity_insert in sites/all/modules/ulmus/filefield_paths/filefield_paths.module
Implements hook_entity_insert().
_filefield_paths_batch_update_process in sites/all/modules/ulmus/filefield_paths/filefield_paths.module

File

sites/all/modules/ulmus/filefield_paths/filefield_paths.module, line 236
Contains core functions for the File (Field) Paths module.

Code

function filefield_paths_entity_update($entity, $type) {
  $processed = FALSE;
  $field_types = _filefield_paths_get_field_types();
  $entity_info = entity_get_info($type);
  $bundle_name = !empty($entity_info['entity keys']['bundle']) ? $entity->{$entity_info['entity keys']['bundle']} : $type;
  if ($entity_info['fieldable']) {
    foreach (field_info_fields($type, $bundle_name) as $field) {
      if (in_array($field['type'], array_keys($field_types))) {
        $files = array();
        $instance = field_info_instance($type, $field['field_name'], $bundle_name);
        $enabled = (isset($instance['settings']['filefield_paths_enabled']) && $instance['settings']['filefield_paths_enabled']) || !isset($instance['settings']['filefield_paths_enabled']);
        if ($enabled && isset($entity->{$field['field_name']})) {
          foreach ($entity->{$field['field_name']} as $langcode => &$deltas) {
            foreach ($deltas as $delta => &$file) {
              // Prepare file.
              if (function_exists($function = "{$field['module']}_field_load")) {
                $items = array(array(&$file));
                $function($type, array($entity), $field, array($instance), $langcode, $items, FIELD_LOAD_CURRENT);
              }
              $files[] = &$file;
            }
            // Invoke hook_filefield_paths_process_file().
            foreach (module_implements('filefield_paths_process_file') as $module) {
              if (function_exists($function = "{$module}_filefield_paths_process_file")) {
                $processed = TRUE;
                $function($type, $entity, $field, $instance, $langcode, $files);
              }
            }
          }
        }
      }
    }

    if ($processed) {
      if (isset($entity->revision)) {
        // Remember revision flag.
        $revision = $entity->revision;
        // Remove revision flag as long as fields already processed it, and no need
        // to create new revision for moved files.
        $entity->revision = FALSE;
      }
      // Save any changes back to the database.
      $entity->original = isset($entity->original) ? $entity->original : NULL;
      field_attach_update($type, $entity);
      if (isset($entity->revision)) {
        // Restore revision flag so that other modules can process it if needed.
        $entity->revision = $revision;
      }
    }
  }
}