From c0030f395953143746c771be7f72818d70f1cde4 Mon Sep 17 00:00:00 2001 From: Vasile Chindris Date: Mon, 18 Nov 2024 15:17:47 +0200 Subject: [PATCH] chore(SLB-486): added the custom drupalTranslatedString directive --- packages/drupal/custom/directives.graphql | 8 +++++ .../Directive/DrupalTranslatedStrings.php | 33 +++++++++++++++++++ packages/schema/src/schema.graphql | 1 + 3 files changed, 42 insertions(+) create mode 100644 packages/drupal/custom/src/Plugin/GraphQL/Directive/DrupalTranslatedStrings.php diff --git a/packages/drupal/custom/directives.graphql b/packages/drupal/custom/directives.graphql index a8500b596..4517f6a46 100644 --- a/packages/drupal/custom/directives.graphql +++ b/packages/drupal/custom/directives.graphql @@ -25,3 +25,11 @@ Provided by the "custom" module. Implemented in "Drupal\custom\Plugin\GraphQL\Directive\PEntityEditLink". """ directive @resolveEntityEditLink repeatable on FIELD_DEFINITION | SCALAR | UNION | ENUM | INTERFACE | OBJECT + +""" +Resolves the translated strings. + +Provided by the "custom" module. +Implemented in "Drupal\custom\Plugin\GraphQL\Directive\DrupalTranslatedStrings". +""" +directive @drupalTranslatedStrings repeatable on FIELD_DEFINITION | SCALAR | UNION | ENUM | INTERFACE | OBJECT diff --git a/packages/drupal/custom/src/Plugin/GraphQL/Directive/DrupalTranslatedStrings.php b/packages/drupal/custom/src/Plugin/GraphQL/Directive/DrupalTranslatedStrings.php new file mode 100644 index 000000000..0f0176c28 --- /dev/null +++ b/packages/drupal/custom/src/Plugin/GraphQL/Directive/DrupalTranslatedStrings.php @@ -0,0 +1,33 @@ +getTranslations(['context' => 'website', 'translated' => TRUE]); + return $builder->fromValue(array_map(function($item) { + return [ + '__typename' => 'DrupalTranslatableString', + 'source' => $item->source, + 'language' => $item->language, + 'translation' => $item->translation, + ]; + }, $translations)); + } + +} diff --git a/packages/schema/src/schema.graphql b/packages/schema/src/schema.graphql index 0aca55a91..298421291 100644 --- a/packages/schema/src/schema.graphql +++ b/packages/schema/src/schema.graphql @@ -451,6 +451,7 @@ type Query { stringTranslations: [TranslatableString!] @gatsbyNodes(type: "TranslatableString") + @drupalTranslatedStrings } type Mutation {