Since eva is now supposed to have the ability to work with any type of entity, I created a view that would get attached to taxonomy terms. When I go to display settings, I see that I can set where it appears and that all seems to work. However, when I go to the actual term page where this would appear, it doesn't show up. I tried it with setting some dummy header content to get shown without any luck. In trying to figure out what is going on, I found out that the taxonomy module doesn't actually invoke hook_entity_view so nothing can actually tie into it! While it seems like a core bug in some ways, it also seems like perhaps the better way to solve this would be by implementing the functionality in hook_entity_views_alter? As a note, comment, user, node are the only entities that invoke hook_entity_view. Any other entities would have to invoke it for what is currently there to work.

Comments

btmash’s picture

Ok..so I figured out a way around it. But I can now see why eva did not go the route of hook_entity_views_alter or something else - the entity variable across the various modules that implement that are inconsistent (see #1170198: The build variable name for the entity should be the same regardless of type of entity.). So my solution to show taxonomy fields from eva was as follows:

/**
 * Implements hook_entity_view_alter().
 * I am adding this because only a few of the entities actually invoke hook_entity_view().
 */
function eva_entity_view_alter(&$build, $type) {
  if (!in_array($type, array('comment', 'node', 'user'))) {
    $view_mode = $build['#view_mode'];
    $language = $build['#language'];
    if ($type == 'taxonomy_term') {
      $entity = $build['#term'];
    }
    else {
      // Since this is so messed up, only tackle taxonomy until we figure out
      // sustainable solution.
      return;
    }
    $entity_data = entity_get_info($type);
    $entity_ids = entity_extract_ids($type, $entity);
    $settings = field_view_mode_settings($type, $entity_ids[2]);
    $fields = field_extra_fields_get_display($type, $entity_ids[2], $view_mode);
    $views = eva_get_views($type);

    foreach ($views as $info) {
      $longname = $info['name'] .'_'. $info['display'];
      if (isset($fields[$longname]) && $fields[$longname]['visible']) {
        if ($view = views_get_view($info['name'])) {
          $view->set_display($info['display']);
          if ($view->access($info['display'])) {
            $view->current_entity = $entity;
            $result = $view->execute_display($info['display']);
            if (!empty($result)) {
              $build[$longname] = array(
                '#markup' => $result,
                '#weight' => $fields[$longname]['weight'],
              );
            }
          }
        }
      }
    }
  }
}

Any help from the community regarding this issue would be greatly appreciated.

eaton’s picture

Status: Active » Fixed

BTMash, thanks for the patch. I'm definitely going to give it a spin: I did switch it to use a special case for each entity type that requires this handling; there's little enough code that's shared across the cases, and I figure it can be refactored once a second or third example of this pattern appears.

Status: Fixed » Closed (fixed)

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

kiramarch’s picture

Is this patch included in the latest version of EVA? I'm experiencing the same problem (described in good detail here), and I'm using 7.x-1.2. Thanks!

mkadin’s picture

Yes, the use of hook_entity_view_alter() is central to EVA at this juncture.

kiramarch’s picture

So, mkadin -- does this mean the problem that I'm seeing is a new one?

If so, would it be appropriate to re-open this thread? And what other info can I provide to help illuminate the problem? Thanks!

mkadin’s picture

Yeah, I think this particular issue is settled. Please re-open another issue, preferably with a good description of your fields / content types and an export of your view.