Commit af9a2f68 authored by Fran Garcia-Linares's avatar Fran Garcia-Linares Committed by Damien McKenna
Browse files

Issue #3136075 by s_leu, fjgarlin, mirom, DamienMcKenna: D9 Compatibility -...

Issue #3136075 by s_leu, fjgarlin, mirom, DamienMcKenna: D9 Compatibility - pre_render should be method implementing TrustedCallbackInterface.
parent 200ca433
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ Metatag 8.x-1.x-dev, xxxx-xx-xx
  OgImageWidth.php file.
#3158613 by huzooka, DamienMcKenna, Wim Leers: Metatag field instance migration
  source plugins report incorrect number of items.
#3136075 by s_leu, fjgarlin, mirom, DamienMcKenna: D9 Compatibility -
  pre_render should be method implementing TrustedCallbackInterface.


Metatag 8.x-1.13, 2020-04-21
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
  },
  "require-dev": {
    "drupal/redirect": "1.x-dev",
    "drupal/page_manager": "4.x-dev"
    "drupal/page_manager": "4.x-dev",
    "drupal/panelizer": "4.x-dev"
  }
}
+3 −1
Original line number Diff line number Diff line
@@ -230,7 +230,9 @@ function metatag_entity_view_alter(array &$build, EntityInterface $entity, Entit
  // called too early, where meta links are not yet set.
  // @see \Drupal\node\Controller\NodeController::view
  if ($display->getThirdPartySetting('panelizer', 'enable', FALSE)) {
    $build['#pre_render'][] = '_metatag_panelizer_pre_render';
    $build['#pre_render'][] = function (array $element) {
      return _metatag_panelizer_pre_render($element);
    };
    return;
  }

+72 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\metatag\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Verify that the JSON output from core works as intended.
 *
 * @group panelizer_metatag
 */
class MetatagPanelizerTest extends BrowserTestBase {

  // Contains helper methods.
  use MetatagHelperTrait;

  /**
   * {@inheritdoc}
   */
  public static $modules = [
    // Modules for core functionality.
    'node',
    'field',
    'field_ui',
    'user',

    // Contrib dependencies.
    'panelizer',
    'token',

    // This module.
    'metatag',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'bartik';

  /**
   * Create an entity, view its JSON output, confirm Metatag data exists.
   */
  public function testPanelizerMetatagPreRender() {
    /* @var\Drupal\node\NodeInterface $node */
    $title = 'Panelizer Metatag Test Title';
    $body = 'Testing JSON output for a content type';
    $node = $this->createContentTypeNode($title, $body);
    $url = $node->toUrl();

    // Initiate session with a user who can manage metatags.
    $permissions = ['administer node display', 'administer meta tags'];
    $account = $this->drupalCreateUser($permissions);
    $this->drupalLogin($account);

    // Load the node's page.
    $this->drupalPostForm(
      'admin/structure/types/manage/metatag_test/display',
      ['panelizer[enable]' => TRUE],
      'Save'
    );

    $this->drupalGet('admin/structure/types/manage/metatag_test/display');
    $this->assertSession()->checkboxChecked('panelizer[enable]');

    $this->drupalGet($url);
    $this->assertSession()->elementContains('css', 'title', $title . ' | Drupal');
    $xpath = $this->xpath("//link[@rel='canonical']");
    self::assertEquals((string) $xpath[0]->getAttribute('href'), $url->toString());
    self::assertEquals(count($xpath), 1);
  }

}