Commit 37a2bb43 authored by Ronino's avatar Ronino Committed by Damien McKenna
Browse files

Issue #3037874 by Ronino, DamienMcKenna: Build meta tags for panels much later...

Issue #3037874 by Ronino, DamienMcKenna: Build meta tags for panels much later like metatag and metatag_views do so they can be altered after page data has been processed.
parent c472b223
Loading
Loading
Loading
Loading
+3 −0
Changes for CHANGELOG.txt: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@ Metatag 7.x-1.xx, 2022-xx-xx
  given, called in metatag/metatag.admin.inc.
#3274588 by Dmitrii_Zadorozhnyi, DamienMcKenna, loon: PHP warnings during static
  code analysis using Phan.
#3037874 by Ronino, DamienMcKenna: Build meta tags for panels much later like
  metatag and metatag_views do so they can be altered after page data has been
  processed.


Metatag 7.x-1.30, 2022-07-27
+28 −20
Changes for metatag_panels/metatag_panels.module: 28 added lines, 20 removed lines.
Original line number Diff line number Diff line
@@ -135,13 +135,37 @@ function metatag_panels_form_submit($form, $form_state) {
 * Implements hook_ctools_render_alter().
 */
function metatag_panels_ctools_render_alter($info, $page, $context) {
  // Save the data necessary for metatag_panels_page_build() to build the meta
  // tags later. Don't build them here yet as this is before any
  // hook_page_build() has run which means some data to alter the meta tags in
  // hook_metatag_metatags_view() might not exist yet.
  $static = &drupal_static('metatag_panels');
  $static['context'] = $context;
  $static['info'] = $info;
}

/**
 * Implements hook_page_build().
 *
 * @see metatag_panels_ctools_render_alter()
 */
function metatag_panels_page_build(&$page) {
  // By default do not add meta tags to admin pages. To enable meta tags on
  // admin pages set the 'metatag_tag_admin_pages' variable to TRUE.
  if (path_is_admin(current_path()) && !variable_get('metatag_tag_admin_pages', FALSE)) {
    return;
  }

  $output = &drupal_static('metatag_panels');
  $static = drupal_static('metatag_panels');

  // If metatag_panels_ctools_render_alter() wasn't called, there's no data to
  // process.
  if (empty($static)) {
    return;
  }

  $context = $static['context'];
  $info = $static['info'];

  $handler = $context['handler'];

@@ -227,29 +251,13 @@ function metatag_panels_ctools_render_alter($info, $page, $context) {
      $tag_output = $metatag_instance->getElement($options);
      // Don't output the pager if that's all there is.
      if ($tag_output != $current_pager) {
        $output[$metatag] = $tag_output;
      }
        $metatags[$metatag] = $tag_output;
      }
    }

  // Give third-parties the opportunity to alter the metatag for a given
  // instance.
  drupal_alter('metatag_metatags_view', $output, $options['instance']);
}

/**
 * Implements hook_page_build().
 *
 * @see metatag_panels_ctools_render_alter()
 */
function metatag_panels_page_build(&$page) {
  // By default do not add meta tags to admin pages. To enable meta tags on
  // admin pages set the 'metatag_tag_admin_pages' variable to TRUE.
  if (path_is_admin(current_path()) && !variable_get('metatag_tag_admin_pages', FALSE)) {
    return;
  }

  $metatags = drupal_static('metatag_panels');
  // Trigger hook_metatag_metatags_view_alter().
  drupal_alter('metatag_metatags_view', $metatags, $options['instance']);

  if (!empty($metatags)) {
    // The page region can be changed.