From 9fd7dd69f55cae876b69497ac2cce9a89a057599 Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Tue, 11 Apr 2023 07:14:21 +1000 Subject: [PATCH] Revert "Issue #3134349 by sleitner, yookoala, sharma.amitt16, Akram Khan, sahil.goyal, swatichouhan012, s_leu, penyaskito, smustgrave, joachim, larowlan: \Drupal\language\LanguageNegotiator does not handle PluginNotFoundException and break the site completely" This reverts commit b279c9946176bfc7a7dd5b13138a8b6ef8d8de95. --- .../language/src/LanguageNegotiator.php | 13 +---- .../Kernel/LanguageNegotiatorPluginTest.php | 54 ------------------- 2 files changed, 2 insertions(+), 65 deletions(-) delete mode 100644 core/modules/language/tests/src/Kernel/LanguageNegotiatorPluginTest.php diff --git a/core/modules/language/src/LanguageNegotiator.php b/core/modules/language/src/LanguageNegotiator.php index 72bf83cea9e6..c4e083ab1a30 100644 --- a/core/modules/language/src/LanguageNegotiator.php +++ b/core/modules/language/src/LanguageNegotiator.php @@ -2,10 +2,8 @@ namespace Drupal\language; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Logger\LoggerChannelTrait; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Site\Settings; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; @@ -15,7 +13,6 @@ * Class responsible for performing language negotiation. */ class LanguageNegotiator implements LanguageNegotiatorInterface { - use LoggerChannelTrait; /** * The language negotiation method plugin manager. @@ -79,7 +76,7 @@ class LanguageNegotiator implements LanguageNegotiatorInterface { * @param \Drupal\language\ConfigurableLanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Component\Plugin\PluginManagerInterface $negotiator_manager - * The language negotiation methods plugin manager. + * The language negotiation methods plugin manager * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The configuration factory. * @param \Drupal\Core\Site\Settings $settings @@ -133,13 +130,7 @@ public function initializeType($type) { // and return the first valid language found. foreach ($this->getEnabledNegotiators($type) as $method_id => $info) { if (!isset($this->negotiatedLanguages[$method_id])) { - try { - $this->negotiatedLanguages[$method_id] = $this->negotiateLanguage($type, $method_id); - } - catch (PluginNotFoundException $e) { - // If a plugin is not found, log the error so user can handle it. - $this->getLogger('language')->error($e->getMessage()); - } + $this->negotiatedLanguages[$method_id] = $this->negotiateLanguage($type, $method_id); } // Since objects are references, we need to return a clone to prevent diff --git a/core/modules/language/tests/src/Kernel/LanguageNegotiatorPluginTest.php b/core/modules/language/tests/src/Kernel/LanguageNegotiatorPluginTest.php deleted file mode 100644 index a355071da570..000000000000 --- a/core/modules/language/tests/src/Kernel/LanguageNegotiatorPluginTest.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Drupal\Tests\language\Kernel; - -use ColinODell\PsrTestLogger\TestLogger; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Logger\LoggerChannelFactory; -use Drupal\KernelTests\KernelTestBase; - -/** - * Tests PluginNotFoundException. - * - * @group language - */ -class LanguageNegotiatorPluginTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = ['language', 'user']; - - /** - * Tests for PluginNotFoundException. - */ - public function testLanguageNegotiatorNoPlugin() { - $logger = new TestLogger(); - $logger_factory = $this->createMock(LoggerChannelFactory::class); - $logger_factory->expects($this->once()) - ->method('get') - ->with('language') - ->willReturn($logger); - $this->container->set('logger.factory', $logger_factory); - $this->installEntitySchema('user'); - - // Test unavailable plugin. - $config = $this->config('language.types'); - $config->set('configurable', [LanguageInterface::TYPE_URL]); - $config->set('negotiation.language_url.enabled', [ - self::CLASS => -3, - ]); - $config->save(); - $languageNegotiator = $this->container->get('language_negotiator'); - $languageNegotiator->setCurrentUser($this->prophesize('Drupal\Core\Session\AccountInterface')->reveal()); - try { - $languageNegotiator->initializeType(LanguageInterface::TYPE_URL); - } - catch (PluginNotFoundException $exception) { - $this->fail('Plugin not found exception unhandled.'); - } - $this->assertTrue($logger->hasErrorThatContains('The "Drupal\Tests\language\Kernel\LanguageNegotiatorPluginTest" plugin does not exist.')); - } - -} -- GitLab