Commit b3a1ff84 authored by Joshua Boltz's avatar Joshua Boltz Committed by Damien McKenna
Browse files

Issue #3314204 by DamienMcKenna, joshua.boltz: Handling of single vs...

Issue #3314204 by DamienMcKenna, joshua.boltz: Handling of single vs multiple-value metatags with Search API integration.
parent 9a405d6e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ Metatag 8.x-1.x-dev, 2022-xx-xx
#3323961 by ressa, DamienMcKenna: Update README.md with new standard format.
#3332348 by DamienMcKenna: Add function for getting list of overridden meta tags
  for a given entity.
#3314204 by DamienMcKenna, joshua.boltz: Handling of single vs multiple-value
  metatags with Search API integration.


Metatag 8.x-1.22, 2022-09-29
+17 −23
Original line number Diff line number Diff line
@@ -72,30 +72,24 @@ class IndividualTag extends TypedData {
    ];
    $values = $metatagManager->generateRawElements($tags, $entity);

    if (!empty($values)) {
      $all_tags = [];
      foreach (\Drupal::service('plugin.manager.metatag.tag')->getDefinitions() as $tag_name => $tag_spec) {
        $all_tags[$tag_name] = new $tag_spec['class']([], $tag_name, $tag_spec);
      }

    // If this tag has a value set the property value.
    if (isset($values[$property_name])) {
      $attribute_name = $all_tags[$property_name]->getHtmlValueAttribute();

      // It should be possible to extract the HTML attribute that stores the
      // value, but in some cases it might not be possible.
      if (isset($values[$property_name]['#attributes'][$attribute_name])) {
        $this->value = $values[$property_name]['#attributes'][$attribute_name];
      // Because the values are an array, loop through the output to to support
      // both single and multi-value tags.
      $tag = $all_tags[$property_name];
      if (!empty($values)) {
        $attribute_name = $tag->getHtmlValueAttribute();
        $attribute_values = [];
        foreach ($values as $value) {
          if (isset($value['#attributes'][$attribute_name])) {
            $attribute_values[] = $value['#attributes'][$attribute_name];
          }
      else {
        \Drupal::service('logger.factory')
          ->get('metatag')
          ->notice('Attribute value not mapped for "%property_name" - entity_type: %type, entity_bundle: %bundle, id: %id. See src/TypedData/Metatags.php.', [
            '%property_name' => $property_name,
            '%type' => $entity->getEntityTypeId(),
            '%bundle' => $entity->bundle(),
            '%id' => $entity->id(),
          ]);
        return FALSE;
        }
        $this->value = implode(' ', $attribute_values);
      }
    }