@@ 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 |
@@ 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 |
@@ 26-62 (lines=37) @@ | ||
23 | * } |
|
24 | * ) |
|
25 | */ |
|
26 | class MenuByName extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
27 | use DependencySerializationTrait; |
|
28 | ||
29 | /** |
|
30 | * The entity type manager. |
|
31 | * |
|
32 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
33 | */ |
|
34 | protected $entityTypeManager; |
|
35 | ||
36 | /** |
|
37 | * {@inheritdoc} |
|
38 | */ |
|
39 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
40 | return new static($configuration, $pluginId, $pluginDefinition, $container->get('entity_type.manager')); |
|
41 | } |
|
42 | ||
43 | /** |
|
44 | * {@inheritdoc} |
|
45 | */ |
|
46 | public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityTypeManagerInterface $entityTypeManager) { |
|
47 | $this->entityTypeManager = $entityTypeManager; |
|
48 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * {@inheritdoc} |
|
53 | */ |
|
54 | public function resolveValues($value, array $args, ResolveInfo $info) { |
|
55 | $entity = $this->entityTypeManager->getStorage('menu')->load($args['name']); |
|
56 | ||
57 | if ($entity instanceof MenuInterface) { |
|
58 | yield $entity; |
|
59 | } |
|
60 | } |
|
61 | ||
62 | } |
|
63 |