If using Metatag module, metatags aren't being displayed in views used by taxonomy display.

See this issue #1837660: Integration with Metatag and what module's author says in comment #4

At this point I don't think Metatag should need to handle every possible scenario - if there isn't a simple & generic way of handling this using the data from entity_get_info() then the other module, i.e. Taxonomy Display, should do the integration.

¿Is he right? ¿Could Taxonomy Display solve this problem?

I've read another issues talking about views integration with Metatag, but i think this is different (at least in theory), because we don't have to set anyting, we already have metatag information to show: the metatags that would show the core term display page.

Thank you in advance.

Comments

codycraven’s picture

Category: bug » feature

Changing to a feature request. I haven't looked at metatag's implementation but if my assumption is right we could support it in taxonomy_display.

alexp999’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Issue summary: View changes
Status: Active » Needs work

I have written the following hook function to add to taxonomy_display.module which seems to function as expected. Still haven't got my head around writing a patch, sorry:

/**
 * Implements hook_metatag_views_post_render_get_entity().
 */
function taxonomy_display_metatag_views_post_render_get_entity($view) {
  if (isset($view->override_path) && strpos($view->override_path, 'taxonomy/term/') !== FALSE) {
    if (!empty($view->args) && is_numeric($view->args[0])) {
      $id = $view->args[0];
      $entities = entity_load('taxonomy_term', array($id));
      if (!empty($entities)) {
        $entity = array_pop($entities);
        metatag_entity_view($entity, 'taxonomy_term', 'full', NULL, TRUE);
      }
    }
  }
}
alexp999’s picture

When this gets committed:
https://www.drupal.org/node/1783968

The code needs to be:

/**
 * Implements hook_metatag_views_post_render_get_entity().
 */
function taxonomy_display_metatag_views_post_render_get_entity($view) {
  if (isset($view->override_url) && strpos($view->override_url, 'taxonomy/term/') !== FALSE) {
    if (!empty($view->args) && is_numeric($view->args[0])) {
      $id = $view->args[0];
      $entities = entity_load('taxonomy_term', array($id));
      if (!empty($entities)) {
        $entity = array_pop($entities);
        metatag_entity_view($entity, 'taxonomy_term', 'full', NULL, TRUE);
      }
    }
  }
}
lanny heidbreder’s picture

#2 in patch form, untested.

lanny heidbreder’s picture

#3 in patch form, untested.

lanny heidbreder’s picture

StatusFileSize
new967 bytes

Reroll of #4 without the vim-tastic syntax error. This is the code from #2.

I tested it this time, and it seems to work wonderfully! Thanks, alexp999!

alexp999’s picture

Status: Needs work » Needs review

Thanks for making the patches.

vbard’s picture

#6 worked, thanx!

vbard’s picture

After rolling #26 from https://www.drupal.org/node/1783968 had to roll #6 back and re-roll #5 - metatags worked!

vbard’s picture

Hi!
Seems like there is a need for another patch. The issue happens when you have taxonomy_display + facet_api + facetapi_pretty_paths. Metatags works on a term page but when you apply any of the facet filter - they don't. The problem is in Metatag's metatag_entity_view() function. There are some checks that cannot be passed with facetapi_pretty_paths's path. So I grabbed the heart of that function and repeated it in taxonomy_display - no more, no less.

vbard’s picture

vbard’s picture

Sorry, this was my first patches - not a patches actually :)
Here is correct.

vbard’s picture