| @@ 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 | ||
| @@ 27-68 (lines=42) @@ | ||
| 24 | * } |
|
| 25 | * ) |
|
| 26 | */ |
|
| 27 | class EntityTranslation extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
| 28 | ||
| 29 | use DependencySerializationTrait; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * The entity repository. |
|
| 33 | * |
|
| 34 | * @var \Drupal\Core\Entity\EntityRepositoryInterface |
|
| 35 | */ |
|
| 36 | protected $entityRepository; |
|
| 37 | ||
| 38 | /** |
|
| 39 | * {@inheritdoc} |
|
| 40 | */ |
|
| 41 | public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityRepositoryInterface $entityRepository) { |
|
| 42 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
| 43 | ||
| 44 | $this->entityRepository = $entityRepository; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
| 51 | return new static( |
|
| 52 | $configuration, |
|
| 53 | $pluginId, |
|
| 54 | $pluginDefinition, |
|
| 55 | $container->get('entity.repository') |
|
| 56 | ); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | */ |
|
| 62 | public function resolveValues($value, array $args, ResolveInfo $info) { |
|
| 63 | if ($value instanceof EntityInterface) { |
|
| 64 | yield $this->entityRepository->getTranslationFromContext($value, $args['language']); |
|
| 65 | } |
|
| 66 | } |
|
| 67 | ||
| 68 | } |
|
| 69 | ||
| @@ 23-71 (lines=49) @@ | ||
| 20 | * parents = {"ExternalUrl"} |
|
| 21 | * ) |
|
| 22 | */ |
|
| 23 | class ExternalRequest extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
| 24 | use DependencySerializationTrait; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @var \GuzzleHttp\ClientInterface |
|
| 28 | */ |
|
| 29 | protected $httpClient; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * {@inheritdoc} |
|
| 33 | */ |
|
| 34 | public static function create( |
|
| 35 | ContainerInterface $container, |
|
| 36 | array $configuration, |
|
| 37 | $plugin_id, |
|
| 38 | $plugin_definition |
|
| 39 | ) { |
|
| 40 | return new static( |
|
| 41 | $configuration, |
|
| 42 | $plugin_id, |
|
| 43 | $plugin_definition, |
|
| 44 | $container->get('http_client') |
|
| 45 | ); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * {@inheritdoc} |
|
| 50 | */ |
|
| 51 | public function __construct( |
|
| 52 | array $configuration, |
|
| 53 | $pluginId, |
|
| 54 | $pluginDefinition, |
|
| 55 | ClientInterface $httpClient |
|
| 56 | ) { |
|
| 57 | $this->httpClient = $httpClient; |
|
| 58 | parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
| 59 | } |
|
| 60 | ||
| 61 | ||
| 62 | /** |
|
| 63 | * {@inheritdoc} |
|
| 64 | */ |
|
| 65 | protected function resolveValues($value, array $args, ResolveInfo $info) { |
|
| 66 | if ($value instanceof Url) { |
|
| 67 | yield $this->httpClient->request('GET', $value->toString()); |
|
| 68 | } |
|
| 69 | } |
|
| 70 | ||
| 71 | } |
|
| 72 | ||