graphql_core_schema-1.0.x-dev/src/Plugin/GraphQL/DataProducer/CurrentLanguage.php

src/Plugin/GraphQL/DataProducer/CurrentLanguage.php
<?php

namespace Drupal\graphql_core_schema\Plugin\GraphQL\DataProducer;

use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Resolves the current language.
 *
 * @DataProducer(
 *   id = "current_language",
 *   name = @Translation("Current Language"),
 *   description = @Translation("Returns the current language."),
 *   produces = @ContextDefinition("string",
 *     label = @Translation("Language")
 *   ),
 * )
 */
class CurrentLanguage extends DataProducerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * {@inheritdoc}
   */
  public static function create(
    ContainerInterface $container,
    array $configuration,
    $pluginId,
    $pluginDefinition,
  ) {
    return new static(
      $configuration,
      $pluginId,
      $pluginDefinition,
      $container->get('language_manager'),
    );
  }

  /**
   * CurrentLanguage constructor.
   *
   * @param array $configuration
   *   The plugin configuration array.
   * @param string $pluginId
   *   The plugin id.
   * @param mixed $pluginDefinition
   *   The plugin definition.
   * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
   *   The language manager.
   */
  public function __construct(
    array $configuration,
    $pluginId,
    $pluginDefinition,
    protected LanguageManagerInterface $languageManager,
  ) {
    parent::__construct($configuration, $pluginId, $pluginDefinition);
  }

  /**
   * The resolver.
   *
   * @return string
   *   The current language ID.
   */
  public function resolve() {
    return $this->languageManager->getCurrentLanguage()->getId();
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc