LanguageId.php in GraphQL 8.3
File
modules/graphql_core/src/Plugin/GraphQL/Enums/Languages/LanguageId.php
View source
<?php
namespace Drupal\graphql_core\Plugin\GraphQL\Enums\Languages;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\graphql\Plugin\GraphQL\Enums\EnumPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LanguageId extends EnumPluginBase implements ContainerFactoryPluginInterface {
protected $languageManager;
public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
return new static($configuration, $pluginId, $pluginDefinition, $container
->get('language_manager'));
}
public function __construct(array $configuration, $pluginId, $pluginDefinition, LanguageManagerInterface $languageManager) {
parent::__construct($configuration, $pluginId, $pluginDefinition);
$this->languageManager = $languageManager;
}
public function buildEnumValues($definition) {
$values = parent::buildEnumValues($definition);
foreach ($this->languageManager
->getLanguages() as $language) {
$name = str_replace('-', '_', $language
->getId());
$values[strtoupper($name)] = [
'value' => $language
->getId(),
'description' => $language
->getName(),
];
}
return $values;
}
}