diff --git a/src/Plugin/GraphQL/Fields/Entity/EntityMetatags.php b/src/Plugin/GraphQL/Fields/Entity/EntityMetatags.php index d47af22..ce426f4 100644 --- a/src/Plugin/GraphQL/Fields/Entity/EntityMetatags.php +++ b/src/Plugin/GraphQL/Fields/Entity/EntityMetatags.php @@ -2,6 +2,7 @@ namespace Drupal\graphql_metatag\Plugin\GraphQL\Fields\Entity; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -68,11 +69,17 @@ public function __construct( */ protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { if ($value instanceof ContentEntityInterface) { - $tags = $this->metatagManager->tagsFromEntityWithDefaults($value); - $elements = $this->metatagManager->generateRawElements($tags, $value); - - foreach ($elements as $element) { - yield $element; + $tags = metatag_get_tags_from_route($value); + // Trigger hook_metatags_attachments_alter(). + // Allow modules to rendered metatags prior to attaching. + \Drupal::service('module_handler')->alter('metatags_attachments', $tags); + $tags = NestedArray::getValue($tags, ['#attached', 'html_head']) ?: []; + $tags = array_filter($tags, function ($tag) { + return is_array($tag) && in_array(NestedArray::getValue($tag, [0, '#tag']), ['meta', 'link']); + }); + $tags = array_map('reset', $tags); + foreach ($tags as $tag) { + yield $tag; } } } diff --git a/src/Plugin/GraphQL/Fields/InternalUrl/Metatags.php b/src/Plugin/GraphQL/Fields/InternalUrl/Metatags.php index f02e54b..9581750 100644 --- a/src/Plugin/GraphQL/Fields/InternalUrl/Metatags.php +++ b/src/Plugin/GraphQL/Fields/InternalUrl/Metatags.php @@ -71,8 +71,11 @@ protected function resolveValues($value, array $args, ResolveContext $context, R if ($value instanceof Url) { $resolve = $this->subRequestBuffer->add($value, function () { $tags = metatag_get_tags_from_route(); + // Trigger hook_metatags_attachments_alter(). + // Allow modules to rendered metatags prior to attaching. + \Drupal::service('module_handler')->alter('metatags_attachments', $tags); $tags = NestedArray::getValue($tags, ['#attached', 'html_head']) ?: []; - $tags = array_filter($tags, function($tag) { + $tags = array_filter($tags, function ($tag) { return is_array($tag) && in_array(NestedArray::getValue($tag, [0, '#tag']), ['meta', 'link']); });