diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 219b1e2..2dcb873 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -22,6 +22,8 @@ Metatag-7.x-1.x-dev, xxxx-xx-xx #1820374 by DamienMcKenna: Front page $cid_parts did not include the full URL. #1822726 by DamienMcKenna: Ensure the CTools exportables system is loaded. #1818300 by eugene.ilyin, DamienMcKenna: Improved Features integration. +#1151936 by DamienMcKenna: Workaround to trigger metatag_entity_view() on Views + pages if the current page is an entity. Metatag-7.x-1.0-beta1, 2012-10-19 diff --git a/metatag.module b/metatag.module index 39471db..eca7434 100644 --- a/metatag.module +++ b/metatag.module @@ -1322,3 +1322,26 @@ function metatag_features_api() { ); return $components; } + +/** + * Implements hook_views_pre_render(). + */ +function metatag_views_post_render(&$view, &$output, &$cache) { + // Build a shortcut to the current display object. + $display = $view->display[$view->current_display]; + + // Only proceed if this view is a full page, don't process block or other + // Views display objects. + if ($display->display_plugin == 'page') { + // Check if this is an entity display page, if so trigger + // hook_entity_view(). + foreach (entity_get_info() as $entity_name => $entity_type) { + // Entity paths will include an auto-loader that matches the entity's + // name, thus the path will be 'some/path/%entity_name'. + if (isset($entity_type['path']) && ($display->display_options['path'] . $entity_name) == $entity_type['path']) { + $entity = array_pop(entity_load($entity_name, $view->args)); + metatag_entity_view($entity, $entity_name, 'full', NULL); + } + } + } +}