@@ 30-71 (lines=42) @@ | ||
27 | * } |
|
28 | * ) |
|
29 | */ |
|
30 | class EntityTranslation extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
31 | ||
32 | use DependencySerializationTrait; |
|
33 | ||
34 | /** |
|
35 | * The entity repository. |
|
36 | * |
|
37 | * @var \Drupal\Core\Entity\EntityRepositoryInterface |
|
38 | */ |
|
39 | protected $entityRepository; |
|
40 | ||
41 | /** |
|
42 | * {@inheritdoc} |
|
43 | */ |
|
44 | public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityRepositoryInterface $entityRepository) { |
|
45 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
46 | ||
47 | $this->entityRepository = $entityRepository; |
|
48 | } |
|
49 | ||
50 | /** |
|
51 | * {@inheritdoc} |
|
52 | */ |
|
53 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
54 | return new static( |
|
55 | $configuration, |
|
56 | $pluginId, |
|
57 | $pluginDefinition, |
|
58 | $container->get('entity.repository') |
|
59 | ); |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * {@inheritdoc} |
|
64 | */ |
|
65 | public function resolveValues($value, array $args, ResolveInfo $info) { |
|
66 | if ($value instanceof EntityInterface) { |
|
67 | yield $this->entityRepository->getTranslationFromContext($value, $args['language']); |
|
68 | } |
|
69 | } |
|
70 | ||
71 | } |
|
72 |
@@ 27-63 (lines=37) @@ | ||
24 | * } |
|
25 | * ) |
|
26 | */ |
|
27 | class MenuByName extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
28 | use DependencySerializationTrait; |
|
29 | ||
30 | /** |
|
31 | * The entity type manager. |
|
32 | * |
|
33 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
34 | */ |
|
35 | protected $entityTypeManager; |
|
36 | ||
37 | /** |
|
38 | * {@inheritdoc} |
|
39 | */ |
|
40 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
41 | return new static($configuration, $pluginId, $pluginDefinition, $container->get('entity_type.manager')); |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * {@inheritdoc} |
|
46 | */ |
|
47 | public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityTypeManagerInterface $entityTypeManager) { |
|
48 | $this->entityTypeManager = $entityTypeManager; |
|
49 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
50 | } |
|
51 | ||
52 | /** |
|
53 | * {@inheritdoc} |
|
54 | */ |
|
55 | public function resolveValues($value, array $args, ResolveInfo $info) { |
|
56 | $entity = $this->entityTypeManager->getStorage('menu')->load($args['name']); |
|
57 | ||
58 | if ($entity instanceof MenuInterface) { |
|
59 | yield $entity; |
|
60 | } |
|
61 | } |
|
62 | ||
63 | } |
|
64 |
@@ 24-72 (lines=49) @@ | ||
21 | * parents = {"ExternalUrl"} |
|
22 | * ) |
|
23 | */ |
|
24 | class ExternalRequest extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
25 | use DependencySerializationTrait; |
|
26 | ||
27 | /** |
|
28 | * @var \GuzzleHttp\ClientInterface |
|
29 | */ |
|
30 | protected $httpClient; |
|
31 | ||
32 | /** |
|
33 | * {@inheritdoc} |
|
34 | */ |
|
35 | public static function create( |
|
36 | ContainerInterface $container, |
|
37 | array $configuration, |
|
38 | $plugin_id, |
|
39 | $plugin_definition |
|
40 | ) { |
|
41 | return new static( |
|
42 | $configuration, |
|
43 | $plugin_id, |
|
44 | $plugin_definition, |
|
45 | $container->get('http_client') |
|
46 | ); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * {@inheritdoc} |
|
51 | */ |
|
52 | public function __construct( |
|
53 | array $configuration, |
|
54 | $pluginId, |
|
55 | $pluginDefinition, |
|
56 | ClientInterface $httpClient |
|
57 | ) { |
|
58 | $this->httpClient = $httpClient; |
|
59 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
60 | } |
|
61 | ||
62 | ||
63 | /** |
|
64 | * {@inheritdoc} |
|
65 | */ |
|
66 | protected function resolveValues($value, array $args, ResolveInfo $info) { |
|
67 | if ($value instanceof Url) { |
|
68 | yield $this->httpClient->request('GET', $value->toString()); |
|
69 | } |
|
70 | } |
|
71 | ||
72 | } |
|
73 |
@@ 28-64 (lines=37) @@ | ||
25 | * deriver = "Drupal\graphql_core\Plugin\Deriver\Fields\EntityByIdDeriver" |
|
26 | * ) |
|
27 | */ |
|
28 | class EntityById extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
29 | ||
30 | use DependencySerializationTrait; |
|
31 | ||
32 | /** |
|
33 | * @var \Drupal\graphql\GraphQL\Batching\Buffers\EntityBuffer |
|
34 | */ |
|
35 | protected $entityBuffer; |
|
36 | ||
37 | /** |
|
38 | * {@inheritdoc} |
|
39 | */ |
|
40 | public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityBuffer $entityBuffer) { |
|
41 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
42 | $this->entityBuffer = $entityBuffer; |
|
43 | } |
|
44 | ||
45 | /** |
|
46 | * {@inheritdoc} |
|
47 | */ |
|
48 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
49 | return new static( |
|
50 | $configuration, |
|
51 | $pluginId, |
|
52 | $pluginDefinition, |
|
53 | $container->get('graphql.buffer.entity') |
|
54 | ); |
|
55 | } |
|
56 | ||
57 | protected function resolveValues($value, array $args, ResolveInfo $info) { |
|
58 | $resolver = $this->entityBuffer->add($this->getPluginDefinition()['entity_type'], $args['id']); |
|
59 | return function ($value, array $args, ResolveInfo $info) use ($resolver) { |
|
60 | yield $resolver(); |
|
61 | }; |
|
62 | } |
|
63 | ||
64 | } |
|
65 |