ImageStyleId.php in GraphQL 8.3
File
modules/graphql_core/src/Plugin/GraphQL/Enums/Images/ImageStyleId.php
View source
<?php
namespace Drupal\graphql_core\Plugin\GraphQL\Enums\Images;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\graphql\Plugin\GraphQL\Enums\EnumPluginBase;
use Drupal\graphql\Utility\StringHelper;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ImageStyleId extends EnumPluginBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
return new static($configuration, $pluginId, $pluginDefinition, $container
->get('entity_type.manager'));
}
public function __construct(array $configuration, $pluginId, $pluginDefinition, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->entityTypeManager = $entityTypeManager;
}
public function buildEnumValues($definition) {
$items = [];
$storage = $this->entityTypeManager
->getStorage('image_style');
foreach ($storage
->loadMultiple() as $imageStyle) {
$items[StringHelper::upperCase($imageStyle
->id())] = [
'value' => $imageStyle
->id(),
'description' => $imageStyle
->label(),
];
}
return $items;
}
}
Classes
Name |
Description |
ImageStyleId |
Plugin annotation
@GraphQLEnum(
id = "image_style_id",
name = "ImageStyleId",
provider = "image"
) |