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