Skip to content
Snippets Groups Projects
Commit 2f370af9 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2195573 by Xano, eiriksm, heddn, ParisLiakos, Les Lim, Pere Orga,...

Issue #2195573 by Xano, eiriksm, heddn, ParisLiakos, Les Lim, Pere Orga, dinarcon, xjm, alexpott: Add a dedicated @LanguageNegotiation annotation class
parent 9f4d5e84
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Showing
with 93 additions and 11 deletions
<?php
/**
* @file
* Contains \Drupal\language\Annotation\LanguageNegotiation.
*/
namespace Drupal\language\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a language negotiation annotation object.
*
* Plugin Namespace: Plugin\LanguageNegotiation
*
* For a working example, see
* \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser.
*
* @see \Drupal\language\LanguageNegotiator
* @see \Drupal\language\LanguageNegotiationMethodManager
* @see \Drupal\language\LanguageNegotiationMethodInterface
* @see hook_language_negotiation_info_alter()
* @see plugin_api
*
* @Annotation
*/
class LanguageNegotiation extends Plugin {
/**
* The language negotiation plugin ID.
*
* @var string
*/
public $id;
/**
* An array of allowed language types.
*
* If a language negotiation plugin does not specify which language types it
* should be used with, it will be available for all the configurable
* language types.
*
* @var string[]
* An array of language types, such as the
* \Drupal\Core\Language\LanguageInterface::TYPE_* constants.
*/
public $types;
/**
* The default weight of the language negotiation plugin.
*
* @var int
*/
public $weight;
/**
* The human-readable name of the language negotiation plugin.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $name;
/**
* The description of the language negotiation plugin.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $description;
/**
* The route pointing to the plugin's configuration page.
*
* @var string
*/
public $config_route_name;
}
...@@ -28,7 +28,7 @@ class LanguageNegotiationMethodManager extends DefaultPluginManager { ...@@ -28,7 +28,7 @@ class LanguageNegotiationMethodManager extends DefaultPluginManager {
* An object that implements ModuleHandlerInterface * An object that implements ModuleHandlerInterface
*/ */
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/LanguageNegotiation', $namespaces, $module_handler, 'Drupal\language\LanguageNegotiationMethodInterface'); parent::__construct('Plugin/LanguageNegotiation', $namespaces, $module_handler, 'Drupal\language\LanguageNegotiationMethodInterface', 'Drupal\language\Annotation\LanguageNegotiation');
$this->cacheBackend = $cache_backend; $this->cacheBackend = $cache_backend;
$this->cacheKeyPrefix = 'language_negotiation_plugins'; $this->cacheKeyPrefix = 'language_negotiation_plugins';
$this->cacheKey = 'language_negotiation_plugins'; $this->cacheKey = 'language_negotiation_plugins';
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
/** /**
* Class for identifying language from the browser Accept-language HTTP header. * Class for identifying language from the browser Accept-language HTTP header.
* *
* @Plugin( * @LanguageNegotiation(
* id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser::METHOD_ID, * id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser::METHOD_ID,
* weight = -2, * weight = -2,
* name = @Translation("Browser"), * name = @Translation("Browser"),
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/** /**
* Class for identifying language from a selected language. * Class for identifying language from a selected language.
* *
* @Plugin( * @LanguageNegotiation(
* id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected::METHOD_ID, * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected::METHOD_ID,
* weight = 12, * weight = 12,
* name = @Translation("Selected language"), * name = @Translation("Selected language"),
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
/** /**
* Identify language from a request/session parameter. * Identify language from a request/session parameter.
* *
* @Plugin( * @LanguageNegotiation(
* id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::METHOD_ID, * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::METHOD_ID,
* weight = -6, * weight = -6,
* name = @Translation("Session"), * name = @Translation("Session"),
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/** /**
* Identifies the language from the interface text language selected for page. * Identifies the language from the interface text language selected for page.
* *
* @Plugin( * @LanguageNegotiation(
* id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI::METHOD_ID, * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI::METHOD_ID,
* types = {Drupal\Core\Language\LanguageInterface::TYPE_CONTENT}, * types = {Drupal\Core\Language\LanguageInterface::TYPE_CONTENT},
* weight = 9, * weight = 9,
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
/** /**
* Class for identifying language via URL prefix or domain. * Class for identifying language via URL prefix or domain.
* *
* @Plugin( * @LanguageNegotiation(
* id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::METHOD_ID, * id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::METHOD_ID,
* types = {\Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE, * types = {\Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE,
* \Drupal\Core\Language\LanguageInterface::TYPE_CONTENT, * \Drupal\Core\Language\LanguageInterface::TYPE_CONTENT,
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
* fixed. This is done by introducing a prefix or domain in the rendered * fixed. This is done by introducing a prefix or domain in the rendered
* page matching the detected interface language. * page matching the detected interface language.
* *
* @Plugin( * @LanguageNegotiation(
* id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback::METHOD_ID, * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback::METHOD_ID,
* types = {Drupal\Core\Language\LanguageInterface::TYPE_URL}, * types = {Drupal\Core\Language\LanguageInterface::TYPE_URL},
* weight = 8, * weight = 8,
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/** /**
* Class for identifying language from a selected language. * Class for identifying language from a selected language.
* *
* @Plugin( * @LanguageNegotiation(
* id = "test_language_negotiation_method", * id = "test_language_negotiation_method",
* weight = -10, * weight = -10,
* name = @Translation("Test"), * name = @Translation("Test"),
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
/** /**
* Class for identifying language from a selected language. * Class for identifying language from a selected language.
* *
* @Plugin( * @LanguageNegotiation(
* id = "test_language_negotiation_method_ts", * id = "test_language_negotiation_method_ts",
* weight = -10, * weight = -10,
* name = @Translation("Type-specific test"), * name = @Translation("Type-specific test"),
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/** /**
* Class for identifying language from the user preferences. * Class for identifying language from the user preferences.
* *
* @Plugin( * @LanguageNegotiation(
* id = \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser::METHOD_ID, * id = \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser::METHOD_ID,
* weight = -4, * weight = -4,
* name = @Translation("User"), * name = @Translation("User"),
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/** /**
* Identifies admin language from the user preferences. * Identifies admin language from the user preferences.
* *
* @Plugin( * @LanguageNegotiation(
* id = Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::METHOD_ID, * id = Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::METHOD_ID,
* types = {Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE}, * types = {Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE},
* weight = -10, * weight = -10,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment