Hi:

This module uses a function from entity module (entity_load_single) but entity module is not a dependency for image cache actions.

See utility.inc line 434:

/**
 * Load additional data - Fully load the entities that actually use the given file, with all their data.
 *
 * Replaces the full entity object in place of the placeholder object that file_get_file_references() gives us.
 */
function imagecache_actions_entities_from_references(&$fields) {
  foreach ($fields as $fid => $field_ids) {
    foreach ($field_ids as $field_id => $entity_types) {
      foreach ($entity_types as $entity_type => $entity_instances) {
        #$entities = entity_load($entity_type, array_keys($entity_instances));
        foreach ($entity_instances as $entity_id => $entity) {
          $entity = entity_load_single($entity_type, $entity_id);
          // Add this extra data to the return info, replacing the lightweight version
          $fields[$fid][$field_id][$entity_type][$entity_id] = $entity;

          #// Also bubble up the field info so it's easier to get at? No, that's way too deep.
          #// Still, it would be a common use-case to fetch the 'title' from that file.
          #// Don't know WHICH of the files our target file is yet, so need to scan. Boring
          #$entity_refs = $references[$fid][$field_id][$entity_type][$entity_id][$field_id][$entity->language];
          #foreach ($entity_refs as $delta => $file_details) {
          #  if ($file_details['fid'] == $fid) {
          #    // Found it. This has the alt and title metadata we expect.
            #    $file_info = $file_details;
            #    // Now what?
          #  }
          #} // Scan actual field data to find the file again.

        } // All actual entities
      } // All types of entity that ref the file
    } // All references to this file
  } // All entries for this file found in the db (expected to be only 1)
}

This function has to be changed or entity added as a dependency (I think).

Thanks!

Comments

dman’s picture

That is correct.
Entity.module is a *soft* dependency.
It should not be required to enable the module, as the action can perform without it. Well, it should work in a limited fashion, if appropriate checks are made. If it's currently causing errors (?) then some module_exists() check should be added.

But if you DO enable entity module then more rich data becomes available to work with.

At this level, it probably deserves a dependency * recommendation* that we could maybe put in the site status report or the config page. But not having it does not make the module unusable.

neurojavi’s picture

I agree, a dependency recomendation and a check to avoid errors would be enough ...
I had no problem but I discover this and wanted you to know.

Thanks.-

fietserwin’s picture

Title: Dependency from entity module not documented » Remove dependency from entity module
Version: 7.x-1.0 » 7.x-1.x-dev
Assigned: Unassigned » fietserwin

entity_load_single() is a very simple wrapper around entity_load(). It just makes an array with the single entity id and retrieves the first element of the result array. So I just inlined that function.

However, it looks like imagecache_actions_entities_from_references() is only called from imagecache_actions_fields_from_filepath() which in turn is not called at all. I think that on integrating image_effects_text, that had its own variant of this functionality, these 2 functions became outdated. So for now I marked them deprecated.

@dman: can you tell if this function is supposed to be called by custom actions or was this function called by our own code before the custom action takes off? In the latter case I want to completely remove them, in the former case I want to move users to the new function by a more explicit fail message.

The above change has been committed, but I leave this issue open for the remaining question.

fietserwin’s picture

Assigned: fietserwin » Unassigned
Status: Active » Fixed

Removed the deprecated functions imagecache_actions_entities_from_references() and imagecache_actions_fields_from_filepath().

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.