|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\GraphQL\Enums\Images; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
6
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
7
|
|
|
use Drupal\graphql\Plugin\GraphQL\Enums\EnumPluginBase; |
|
8
|
|
|
use Drupal\graphql\Plugin\SchemaBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @GraphQLEnum( |
|
13
|
|
|
* id = "image_style_id", |
|
14
|
|
|
* name = "ImageStyleId", |
|
15
|
|
|
* provider = "image" |
|
16
|
|
|
* ) |
|
17
|
|
|
*/ |
|
18
|
|
|
class ImageStyleId extends EnumPluginBase implements ContainerFactoryPluginInterface { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The entity type manager service. |
|
22
|
|
|
* |
|
23
|
|
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $entityTypeManager; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) { |
|
31
|
|
|
return new static( |
|
32
|
|
|
$configuration, |
|
33
|
|
|
$pluginId, |
|
34
|
|
|
$pluginDefinition, |
|
35
|
|
|
$container->get('entity_type.manager') |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* ImageStyleId constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param array $configuration |
|
43
|
|
|
* The plugin configuration array. |
|
44
|
|
|
* @param string $pluginId |
|
45
|
|
|
* The plugin id. |
|
46
|
|
|
* @param array $pluginDefinition |
|
47
|
|
|
* The plugin definition array. |
|
48
|
|
|
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager |
|
49
|
|
|
* The entity type manager. |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityTypeManagerInterface $entityTypeManager) { |
|
52
|
|
|
parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
53
|
|
|
$this->entityTypeManager = $entityTypeManager; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function buildEnumValues($definition) { |
|
60
|
|
|
$items = []; |
|
61
|
|
|
|
|
62
|
|
|
$storage = $this->entityTypeManager->getStorage('image_style'); |
|
63
|
|
|
foreach ($storage->loadMultiple() as $imageStyle) { |
|
64
|
|
|
$items[strtoupper($imageStyle->id())] = [ |
|
65
|
|
|
'value' => $imageStyle->id(), |
|
66
|
|
|
'description' => $imageStyle->label(), |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $items; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|