You are here

class LanguageNegotiationAdministrationLanguage in Administration Language Negotiation 8

Class for identifying language from a administration language negotiation.

Plugin annotation


@LanguageNegotiation(
  weight = -4,
  name = @Translation("Administration language"),
  description = @Translation("A predefined language is set based on predefined customizable paths."),
  id = Drupal\administration_language_negotiation\Plugin\LanguageNegotiation\LanguageNegotiationAdministrationLanguage::METHOD_ID,
  types = {\Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE},
  config_route_name = "administration_language_negotiation.negotiation_administration_language"
)

Hierarchy

Expanded class hierarchy of LanguageNegotiationAdministrationLanguage

1 file declares its use of LanguageNegotiationAdministrationLanguage
administration_language_negotiation.install in ./administration_language_negotiation.install

File

src/Plugin/LanguageNegotiation/LanguageNegotiationAdministrationLanguage.php, line 25

Namespace

Drupal\administration_language_negotiation\Plugin\LanguageNegotiation
View source
class LanguageNegotiationAdministrationLanguage extends LanguageNegotiationMethodBase implements ContainerFactoryPluginInterface {

  /**
   * The language negotiation method id.
   */
  public const METHOD_ID = 'administration-language-negotiation';

  /**
   * The condition manager.
   *
   * @var \Drupal\administration_language_negotiation\AdministrationLanguageNegotiationConditionManager
   */
  protected $conditionManager;

  /**
   * Constructs a RequestPath condition plugin.
   *
   * @param \Drupal\administration_language_negotiation\AdministrationLanguageNegotiationConditionManager $manager
   *   The current path.
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   */
  public function __construct(AdministrationLanguageNegotiationConditionManager $manager, array $configuration, $plugin_id, array $plugin_definition) {
    $this->conditionManager = $manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($container
      ->get('plugin.manager.administration_language_negotiation_condition'), $configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public function getLangcode(Request $request = NULL) {

    // Run only for allowed users.
    if ($this->currentUser
      ->hasPermission('use administration language negotiation')) {
      $config = $this->config
        ->get('administration_language_negotiation.negotiation');
      $manager = $this->conditionManager;
      foreach ($manager
        ->getDefinitions() as $def) {

        /** @var \Drupal\Core\Executable\ExecutableInterface $condition_plugin */
        $condition_plugin = $manager
          ->createInstance($def['id'], $config
          ->get());
        if (!$manager
          ->execute($condition_plugin)) {
          return $this->currentUser
            ->getPreferredAdminLangcode(FALSE);
        }
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LanguageNegotiationAdministrationLanguage::$conditionManager protected property The condition manager.
LanguageNegotiationAdministrationLanguage::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
LanguageNegotiationAdministrationLanguage::getLangcode public function Performs language negotiation. Overrides LanguageNegotiationMethodInterface::getLangcode
LanguageNegotiationAdministrationLanguage::METHOD_ID public constant The language negotiation method id.
LanguageNegotiationAdministrationLanguage::__construct public function Constructs a RequestPath condition plugin.
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