|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql\Plugin\LanguageNegotiation; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
6
|
|
|
use Drupal\graphql\GraphQLLanguageContext; |
|
7
|
|
|
use Drupal\language\LanguageNegotiationMethodBase; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class for identifying language from a selected language. |
|
13
|
|
|
* |
|
14
|
|
|
* @LanguageNegotiation( |
|
15
|
|
|
* id = Drupal\graphql\Plugin\LanguageNegotiation\LanguageNegotiationGraphQL::METHOD_ID, |
|
16
|
|
|
* weight = 12, |
|
17
|
|
|
* name = @Translation("GraphQL context"), |
|
18
|
|
|
* description = @Translation("The current GraphQL language context. Only available while executing a query.") |
|
19
|
|
|
* ) |
|
20
|
|
|
*/ |
|
21
|
|
|
class LanguageNegotiationGraphQL extends LanguageNegotiationMethodBase implements ContainerFactoryPluginInterface { |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The graphql language context. |
|
25
|
|
|
* |
|
26
|
|
|
* @var \Drupal\graphql\GraphQLLanguageContext |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $languageContext; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function create( |
|
34
|
|
|
ContainerInterface $container, |
|
35
|
|
|
array $configuration, |
|
36
|
|
|
$plugin_id, |
|
37
|
|
|
$plugin_definition |
|
38
|
|
|
) { |
|
39
|
|
|
return new static($container->get('graphql.language_context')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* LanguageNegotiationGraphQL constructor. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Drupal\graphql\GraphQLLanguageContext $languageContext |
|
46
|
|
|
* Instance of the GraphQL language context. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(GraphQLLanguageContext $languageContext) { |
|
49
|
|
|
$this->languageContext = $languageContext; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The language negotiation method id. |
|
54
|
|
|
*/ |
|
55
|
|
|
const METHOD_ID = 'language-graphql'; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* {@inheritdoc} |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getLangcode(Request $request = NULL) { |
|
61
|
|
|
return $this->languageContext->getCurrentLanguage(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|