diff --git a/core/modules/language/src/Attribute/LanguageNegotiation.php b/core/modules/language/src/Attribute/LanguageNegotiation.php new file mode 100644 index 00000000000..fb26311008a --- /dev/null +++ b/core/modules/language/src/Attribute/LanguageNegotiation.php @@ -0,0 +1,54 @@ +cacheBackend = $cache_backend; $this->setCacheBackend($cache_backend, 'language_negotiation_plugins'); $this->alterInfo('language_negotiation_info'); diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationBrowser.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationBrowser.php index abee150c570..2d4dda4fa8e 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationBrowser.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationBrowser.php @@ -4,21 +4,22 @@ namespace Drupal\language\Plugin\LanguageNegotiation; use Drupal\Component\Utility\UserAgent; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; /** * Class for identifying language from the browser Accept-language HTTP header. - * - * @LanguageNegotiation( - * id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser::METHOD_ID, - * weight = -2, - * name = @Translation("Browser"), - * description = @Translation("Language from the browser's language settings."), - * config_route_name = "language.negotiation_browser" - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationBrowser::METHOD_ID, + name: new TranslatableMarkup('Browser'), + weight: -2, + description: new TranslatableMarkup("Language from the browser's language settings."), + config_route_name: 'language.negotiation_browser' +)] class LanguageNegotiationBrowser extends LanguageNegotiationMethodBase implements ContainerFactoryPluginInterface { /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php index 12f349a461e..efe8cdedee2 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php @@ -4,10 +4,13 @@ namespace Drupal\language\Plugin\LanguageNegotiation; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Drupal\language\LanguageSwitcherInterface; use Drupal\Core\Routing\RouteObjectInterface; @@ -17,15 +20,14 @@ use Symfony\Component\Routing\Route; /** * Class for identifying the content translation language. - * - * @LanguageNegotiation( - * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationContentEntity::METHOD_ID, - * types = {Drupal\Core\Language\LanguageInterface::TYPE_CONTENT}, - * weight = -9, - * name = @Translation("Content language"), - * description = @Translation("Determines the content language from the request parameter named 'language_content_entity'."), - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationContentEntity::METHOD_ID, + name: new TranslatableMarkup('Content language'), + types: [LanguageInterface::TYPE_CONTENT], + weight: -9, + description: new TranslatableMarkup("Determines the content language from the request parameter named 'language_content_entity'.") +)] class LanguageNegotiationContentEntity extends LanguageNegotiationMethodBase implements OutboundPathProcessorInterface, LanguageSwitcherInterface, ContainerFactoryPluginInterface { /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSelected.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSelected.php index 32fc21c616a..ae226cb5cc9 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSelected.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSelected.php @@ -2,20 +2,21 @@ namespace Drupal\language\Plugin\LanguageNegotiation; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Symfony\Component\HttpFoundation\Request; /** * Class for identifying language from a selected language. - * - * @LanguageNegotiation( - * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected::METHOD_ID, - * weight = 12, - * name = @Translation("Selected language"), - * description = @Translation("Language based on a selected language."), - * config_route_name = "language.negotiation_selected" - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationSelected::METHOD_ID, + name: new TranslatableMarkup('Selected language'), + weight: 12, + description: new TranslatableMarkup("Language based on a selected language."), + config_route_name: 'language.negotiation_selected' +)] class LanguageNegotiationSelected extends LanguageNegotiationMethodBase { /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php index daa8cf8acde..b17dd9dfa11 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php @@ -6,7 +6,9 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Drupal\language\LanguageSwitcherInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -15,15 +17,14 @@ use Symfony\Component\HttpFoundation\RequestStack; /** * Identify language from a request/session parameter. - * - * @LanguageNegotiation( - * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession::METHOD_ID, - * weight = -6, - * name = @Translation("Session"), - * description = @Translation("Language from a request/session parameter."), - * config_route_name = "language.negotiation_session" - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationSession::METHOD_ID, + name: new TranslatableMarkup('Session'), + weight: -6, + description: new TranslatableMarkup("Language from a request/session parameter."), + config_route_name: 'language.negotiation_session' +)] class LanguageNegotiationSession extends LanguageNegotiationMethodBase implements OutboundPathProcessorInterface, LanguageSwitcherInterface, ContainerFactoryPluginInterface { /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php index cf699c3baed..130f68fa4b4 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUI.php @@ -2,20 +2,22 @@ namespace Drupal\language\Plugin\LanguageNegotiation; +use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Symfony\Component\HttpFoundation\Request; /** * Identifies the language from the interface text language selected for page. - * - * @LanguageNegotiation( - * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI::METHOD_ID, - * types = {Drupal\Core\Language\LanguageInterface::TYPE_CONTENT}, - * weight = 9, - * name = @Translation("Interface"), - * description = @Translation("Use the detected interface language.") - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationUI::METHOD_ID, + name: new TranslatableMarkup('Interface'), + types: [LanguageInterface::TYPE_CONTENT], + weight: 9, + description: new TranslatableMarkup("Use the detected interface language.") +)] class LanguageNegotiationUI extends LanguageNegotiationMethodBase { /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php index 917e591171f..af5ecd3f8d7 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php @@ -6,25 +6,27 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\PathProcessor\InboundPathProcessorInterface; use Drupal\Core\PathProcessor\OutboundPathProcessorInterface; use Drupal\Core\Render\BubbleableMetadata; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Drupal\language\LanguageSwitcherInterface; use Symfony\Component\HttpFoundation\Request; /** * Class for identifying language via URL prefix or domain. - * - * @LanguageNegotiation( - * id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl::METHOD_ID, - * types = {\Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE, - * \Drupal\Core\Language\LanguageInterface::TYPE_CONTENT, - * \Drupal\Core\Language\LanguageInterface::TYPE_URL}, - * weight = -8, - * name = @Translation("URL"), - * description = @Translation("Language from the URL (Path prefix or domain)."), - * config_route_name = "language.negotiation_url" - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationUrl::METHOD_ID, + name: new TranslatableMarkup('URL'), + types: [LanguageInterface::TYPE_INTERFACE, + LanguageInterface::TYPE_CONTENT, + LanguageInterface::TYPE_URL, + ], + weight: -8, + description: new TranslatableMarkup("Language from the URL (Path prefix or domain)."), + config_route_name: 'language.negotiation_url' +)] class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements InboundPathProcessorInterface, OutboundPathProcessorInterface, LanguageSwitcherInterface { /** diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php index 61a3ecc4714..77f902fe725 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrlFallback.php @@ -2,6 +2,9 @@ namespace Drupal\language\Plugin\LanguageNegotiation; +use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Symfony\Component\HttpFoundation\Request; @@ -25,15 +28,14 @@ use Symfony\Component\HttpFoundation\Request; * requested URL having an empty prefix or domain is an anomaly that must be * fixed. This is done by introducing a prefix or domain in the rendered * page matching the detected interface language. - * - * @LanguageNegotiation( - * id = Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback::METHOD_ID, - * types = {Drupal\Core\Language\LanguageInterface::TYPE_URL}, - * weight = 8, - * name = @Translation("URL fallback"), - * description = @Translation("Use an already detected language for URLs if none is found.") - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationUrlFallback::METHOD_ID, + name: new TranslatableMarkup('URL fallback'), + types: [LanguageInterface::TYPE_URL], + weight: 8, + description: new TranslatableMarkup('Use an already detected language for URLs if none is found.'), +)] class LanguageNegotiationUrlFallback extends LanguageNegotiationMethodBase { /** diff --git a/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTest.php b/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTest.php index 27537758761..36a9d24ae03 100644 --- a/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTest.php +++ b/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTest.php @@ -2,21 +2,25 @@ namespace Drupal\language_test\Plugin\LanguageNegotiation; +use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Symfony\Component\HttpFoundation\Request; /** * Class for identifying language from a selected language. - * - * @LanguageNegotiation( - * id = "test_language_negotiation_method", - * weight = -10, - * name = @Translation("Test"), - * description = @Translation("This is a test language negotiation method."), - * types = {Drupal\Core\Language\LanguageInterface::TYPE_CONTENT, - * "test_language_type", "fixed_test_language_type"} - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationTest::METHOD_ID, + name: new TranslatableMarkup('Test'), + types: [LanguageInterface::TYPE_CONTENT, + 'test_language_type', + 'fixed_test_language_type', + ], + weight: -10, + description: new TranslatableMarkup('This is a test language negotiation method.'), +)] class LanguageNegotiationTest extends LanguageNegotiationMethodBase { /** diff --git a/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php b/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php index 1f730cfca29..9859e0952b2 100644 --- a/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php +++ b/core/modules/language/tests/language_test/src/Plugin/LanguageNegotiation/LanguageNegotiationTestTs.php @@ -2,17 +2,19 @@ namespace Drupal\language_test\Plugin\LanguageNegotiation; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; + /** * Class for identifying language from a selected language. - * - * @LanguageNegotiation( - * id = "test_language_negotiation_method_ts", - * weight = -10, - * name = @Translation("Type-specific test"), - * description = @Translation("This is a test language negotiation method."), - * types = {"test_language_type"} - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationTestTs::METHOD_ID, + name: new TranslatableMarkup('Type-specific test'), + types: ['test_language_type'], + weight: -10, + description: new TranslatableMarkup('This is a test language negotiation method.'), +)] class LanguageNegotiationTestTs extends LanguageNegotiationTest { /** diff --git a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php index 0e8108a9c8d..4f51a396afb 100644 --- a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php +++ b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUser.php @@ -2,19 +2,20 @@ namespace Drupal\user\Plugin\LanguageNegotiation; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Symfony\Component\HttpFoundation\Request; /** * Class for identifying language from the user preferences. - * - * @LanguageNegotiation( - * id = \Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser::METHOD_ID, - * weight = -4, - * name = @Translation("User"), - * description = @Translation("Follow the user's language preference.") - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationUser::METHOD_ID, + name: new TranslatableMarkup('User'), + weight: -4, + description: new TranslatableMarkup("Follow the user's language preference.") +)] class LanguageNegotiationUser extends LanguageNegotiationMethodBase { /** diff --git a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php index 7eba82eec12..a2556662a64 100644 --- a/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php +++ b/core/modules/user/src/Plugin/LanguageNegotiation/LanguageNegotiationUserAdmin.php @@ -2,10 +2,13 @@ namespace Drupal\user\Plugin\LanguageNegotiation; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\PathProcessor\PathProcessorManager; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Routing\AdminContext; use Drupal\Core\Routing\StackedRouteMatchInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\language\Attribute\LanguageNegotiation; use Drupal\language\LanguageNegotiationMethodBase; use Drupal\Core\Routing\RouteObjectInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,15 +19,14 @@ use Symfony\Component\Routing\Matcher\UrlMatcherInterface; /** * Identifies admin language from the user preferences. - * - * @LanguageNegotiation( - * id = Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin::METHOD_ID, - * types = {Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE}, - * weight = -10, - * name = @Translation("Account administration pages"), - * description = @Translation("Account administration pages language setting.") - * ) */ +#[LanguageNegotiation( + id: LanguageNegotiationUserAdmin::METHOD_ID, + name: new TranslatableMarkup('Account administration pages'), + types: [LanguageInterface::TYPE_INTERFACE], + weight: -10, + description: new TranslatableMarkup('Account administration pages language setting.') +)] class LanguageNegotiationUserAdmin extends LanguageNegotiationMethodBase implements ContainerFactoryPluginInterface { /**