Commit acd07c71 authored by Dave Reid's avatar Dave Reid Committed by Damien McKenna
Browse files

Issue #3121289 by Dave Reid, DamienMcKenna: Normalize token types using the...

Issue #3121289 by Dave Reid, DamienMcKenna: Normalize token types using the Token module mapper service.
parent 0b405841
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ By DamienMcKenna: Minor code readability tweak.
#3120981 by DamienMcKenna: NodewordsFieldInstanceTest uses the wrong source
  plugin.
#3120331 by thalles: Add directive docs into support section of composer file.
#3121289 by Dave Reid, DamienMcKenna: Normalize token types using the Token
  module mapper service.


Metatag 8.x-1.11, 2019-12-20
+1 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ services:

  metatag.token:
    class: Drupal\metatag\MetatagToken
    arguments: ['@token']
    arguments: ['@token', '@token.entity_mapper']

  metatag.manager:
    class: Drupal\metatag\MetatagManager
+15 −4
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\metatag;

use Drupal\Core\Utility\Token;
use Drupal\Core\Render\BubbleableMetadata;
use Drupal\token\TokenEntityMapperInterface;

/**
 * Token handling service. Uses core token service or contributed Token.
@@ -17,14 +18,24 @@ class MetatagToken {
   */
  protected $token;

  /**
   * Token entity type mapper service.
   *
   * @var \Drupal\token\TokenEntityMapperInterface
   */
  protected $tokenEntityMapper;

  /**
   * Constructs a new MetatagToken object.
   *
   * @param \Drupal\Core\Utility\Token $token
   *   Token service.
   * @param \Drupal\token\TokenEntityMapperInterface $token_entity_mapper
   *   The token entity type mapper service.
   */
  public function __construct(Token $token) {
  public function __construct(Token $token, TokenEntityMapperInterface $token_entity_mapper) {
    $this->token = $token;
    $this->tokenEntityMapper = $token_entity_mapper;
  }

  /**
@@ -75,11 +86,11 @@ class MetatagToken {
      '#markup' => '<p>' . t('<strong>Configure the meta tags below.</strong><br /> To view a summary of the individual meta tags and the pattern for a specific configuration, click on its name below. Use tokens to avoid redundant meta data and search engine penalization. For example, a \'keyword\' value of "example" will be shown on all content using this configuration, whereas using the [node:field_keywords] automatically inserts the "keywords" values from the current entity (node, term, etc).') . '</p>',
    ];

    // Normalize taxonomy tokens.
    // Normalize token types.
    if (!empty($token_types)) {
      $token_types = array_map(function ($value) {
        return stripos($value, 'taxonomy_') === 0 ? substr($value, strlen('taxonomy_')) : $value;
      }, (array) $token_types);
        return $this->tokenEntityMapper->getTokenTypeForEntityType($value, TRUE);
      }, $token_types);
    }

    $form['tokens'] = [
+12 −6
Original line number Diff line number Diff line
@@ -19,22 +19,28 @@ class MetatagAdminTest extends BrowserTestBase {
   * {@inheritdoc}
   */
  public static $modules = [
    'node',
    'field_ui',
    'test_page_test',
    'token',
    'metatag',

    // Core modules.
    // @see testAvailableConfigEntities
    'block',
    'block_content',
    'comment',
    'contact',
    'field_ui',
    'menu_link_content',
    'menu_ui',
    'node',
    'shortcut',
    'taxonomy',

    // Core test modules.
    'entity_test',
    'test_page_test',

    // Contrib modules.
    'token',

    // This module.
    'metatag',
  ];

  /**
+6 −0
Original line number Diff line number Diff line
@@ -28,7 +28,13 @@ class MetatagSettingsFormTest extends KernelTestBase {
   * @var array
   */
  public static $modules = [
    // Core modules.
    'system',

    // Contrib modules.
    'token',

    // This module.
    'metatag',
  ];

Loading