@@ 24-81 (lines=58) @@ | ||
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 | * ExternalRequest constructor. |
|
51 | * |
|
52 | * @param array $configuration |
|
53 | * The plugin configuration array. |
|
54 | * @param string $pluginId |
|
55 | * The plugin id. |
|
56 | * @param mixed $pluginDefinition |
|
57 | * The plugin definition array. |
|
58 | * @param \GuzzleHttp\ClientInterface $httpClient |
|
59 | * The http client service. |
|
60 | */ |
|
61 | public function __construct( |
|
62 | array $configuration, |
|
63 | $pluginId, |
|
64 | $pluginDefinition, |
|
65 | ClientInterface $httpClient |
|
66 | ) { |
|
67 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
68 | $this->httpClient = $httpClient; |
|
69 | } |
|
70 | ||
71 | ||
72 | /** |
|
73 | * {@inheritdoc} |
|
74 | */ |
|
75 | protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
|
76 | if ($value instanceof Url) { |
|
77 | yield $this->httpClient->request('GET', $value->toString()); |
|
78 | } |
|
79 | } |
|
80 | ||
81 | } |
|
82 |
@@ 32-77 (lines=46) @@ | ||
29 | * response_cache_contexts = {"languages:language_interface"} |
|
30 | * ) |
|
31 | */ |
|
32 | class MenuByName extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
33 | use DependencySerializationTrait; |
|
34 | ||
35 | /** |
|
36 | * The entity type manager. |
|
37 | * |
|
38 | * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
39 | */ |
|
40 | protected $entityTypeManager; |
|
41 | ||
42 | /** |
|
43 | * {@inheritdoc} |
|
44 | */ |
|
45 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
46 | return new static($configuration, $pluginId, $pluginDefinition, $container->get('entity_type.manager')); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * MenuByName constructor. |
|
51 | * |
|
52 | * @param array $configuration |
|
53 | * The plugin configuration array. |
|
54 | * @param string $pluginId |
|
55 | * The plugin id. |
|
56 | * @param mixed $pluginDefinition |
|
57 | * The plugin definition. |
|
58 | * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
|
59 | * The entity type manager service. |
|
60 | */ |
|
61 | public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityTypeManagerInterface $entityTypeManager) { |
|
62 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
63 | $this->entityTypeManager = $entityTypeManager; |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * {@inheritdoc} |
|
68 | */ |
|
69 | public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
|
70 | $entity = $this->entityTypeManager->getStorage('menu')->load($args['name']); |
|
71 | ||
72 | if ($entity instanceof MenuInterface) { |
|
73 | yield $entity; |
|
74 | } |
|
75 | } |
|
76 | ||
77 | } |
|
78 |