You are here

class OperationLanguageNegotiation in GraphQL 8.4

Class for identifying language based on a graphql query.

Plugin annotation


@LanguageNegotiation(
  id = Drupal\graphql\Plugin\LanguageNegotiation\OperationLanguageNegotiation::METHOD_ID,
  weight = -999,
  name = @Translation("GraphQL operation context"),
  description = @Translation("Determines the language in the context of an operation.")
)

Hierarchy

Expanded class hierarchy of OperationLanguageNegotiation

1 file declares its use of OperationLanguageNegotiation
OperationSubscriber.php in src/EventSubscriber/OperationSubscriber.php

File

src/Plugin/LanguageNegotiation/OperationLanguageNegotiation.php, line 19

Namespace

Drupal\graphql\Plugin\LanguageNegotiation
View source
class OperationLanguageNegotiation extends LanguageNegotiationMethodBase {

  /**
   * The language negotiation method id.
   */
  const METHOD_ID = 'language-graphql-operation';

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * The current execution context.
   *
   * @var \Drupal\graphql\GraphQL\Execution\ResolveContext
   */
  protected static $context;

  /**
   * {@inheritdoc}
   */
  public function getLangcode(Request $request = NULL) {
    if (!empty(static::$context)) {
      return static::$context
        ->getContextLanguage();
    }
    return FALSE;
  }

  /**
   * Set the current resolve context statically which contains the language.
   *
   * @param \Drupal\graphql\GraphQL\Execution\ResolveContext $context
   */
  public static function setContext(ResolveContext $context = NULL) : void {
    static::$context = $context;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LanguageNegotiationMethodBase::$config protected property The configuration factory.
LanguageNegotiationMethodBase::$currentUser protected property The current active user.
LanguageNegotiationMethodBase::$languageManager protected property The language manager.
LanguageNegotiationMethodBase::persist public function Notifies the plugin that the language code it returned has been accepted. Overrides LanguageNegotiationMethodInterface::persist 1
LanguageNegotiationMethodBase::setConfig public function Injects the configuration factory. Overrides LanguageNegotiationMethodInterface::setConfig
LanguageNegotiationMethodBase::setCurrentUser public function Injects the current user. Overrides LanguageNegotiationMethodInterface::setCurrentUser
LanguageNegotiationMethodBase::setLanguageManager public function Injects the language manager. Overrides LanguageNegotiationMethodInterface::setLanguageManager
OperationLanguageNegotiation::$context protected static property The current execution context.
OperationLanguageNegotiation::$requestStack protected property The request stack.
OperationLanguageNegotiation::getLangcode public function Performs language negotiation. Overrides LanguageNegotiationMethodInterface::getLangcode
OperationLanguageNegotiation::METHOD_ID constant The language negotiation method id.
OperationLanguageNegotiation::setContext public static function Set the current resolve context statically which contains the language.