diff --git a/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php b/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php index 38ae831..1cdd9ca 100644 --- a/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/CachedUrlGenerator.php @@ -17,7 +17,7 @@ /** * Class used to wrap a UrlGenerator to provide caching of the generated values. */ -class CachedUrlGenerator implements DestructableInterface, UrlGeneratorInterface { +class CachedUrlGenerator implements DestructableInterface, CachedUrlGeneratorInterface { /** * The wrapped URL generator diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php index c45ab6e..ac5d5c8 100644 --- a/core/lib/Drupal/Core/Routing/UrlGenerator.php +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php @@ -370,10 +370,4 @@ protected function getRoute($name) { return $route; } - /** - * {@inheritdoc} - */ - public function clearCache() { - // Nothing to do in this class. - } } diff --git a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php index e526474..62fe1ef 100644 --- a/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php +++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php @@ -199,8 +199,4 @@ public function setBasePath($path); */ public function setScriptPath($path); - /** - * Clears the caches of the URL generator. - */ - public function clearCache(); } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php index 46c39bf..503062c 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php @@ -46,8 +46,7 @@ function testLanguageList() { ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); $this->assertText('French', 'Language added successfully.'); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Add custom language. $langcode = 'xx'; @@ -59,8 +58,7 @@ function testLanguageList() { 'direction' => '0', ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); $this->assertRaw('"edit-languages-' . $langcode .'-weight"', 'Language code found.'); $this->assertText(t($name), 'Test language added.'); @@ -76,13 +74,11 @@ function testLanguageList() { // Clear cached urls in the local process too. $this->container->get('url_generator')->clearCache(); $this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE)), 'Correct page redirection.'); // Ensure we can't delete the default language. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); $this->assertText(t('The default language cannot be deleted.'), 'Failed to delete the default language.'); // Ensure 'Edit' link works. @@ -95,8 +91,7 @@ function testLanguageList() { ); $this->drupalPost('admin/config/regional/language/edit/' . $langcode, $edit, t('Save language')); $this->assertRaw($name, 'The language has been updated.'); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Change back the default language. $edit = array( @@ -113,8 +108,7 @@ function testLanguageList() { $this->drupalGet('admin/config/regional/language/delete/' . $langcode); // First test the 'cancel' link. $this->clickLink(t('Cancel')); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); $this->assertRaw($name, 'The language was not deleted.'); // Delete the language for real. This a confirm form, we do not need any // fields changed. @@ -122,8 +116,7 @@ function testLanguageList() { // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => $name, '%langcode' => $langcode); $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'The test language has been removed.'); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/' . $langcode); $this->assertResponse(404, 'Language no longer found.'); @@ -142,8 +135,7 @@ function testLanguageList() { // We need raw here because %language and %langcode will add HTML. $t_args = array('%language' => 'French', '%langcode' => 'fr'); $this->assertRaw(t('The %language (%langcode) language has been removed.', $t_args), 'Disabled language has been removed.'); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); // Verify that language is no longer found. $this->drupalGet('admin/config/regional/language/delete/fr'); $this->assertResponse(404, 'Language no longer found.'); @@ -165,8 +157,7 @@ function testLanguageList() { $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); // Clear cached urls in the local process too. $this->container->get('url_generator')->clearCache(); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url('admin/config/regional/language', array('absolute' => TRUE)), 'Correct page redirection.'); $this->assertText($name, 'Name found.'); // Check if we can change the default language. @@ -181,8 +172,7 @@ function testLanguageList() { // Clear cached urls in the local process too. $this->container->get('url_generator')->clearCache(); $this->assertNoOptionSelected('edit-site-default-language', 'en', 'Default language updated.'); - // Check for correct page redirection. - $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE))); + $this->assertEqual($this->getUrl(), url($path, array('absolute' => TRUE)), 'Correct page redirection.'); $this->drupalPost('admin/config/regional/language/delete/en', array(), t('Delete')); // We need raw here because %language and %langcode will add HTML. diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 06dcef9..8c6cdf4 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -15,6 +15,7 @@ use Drupal\Core\Database\ConnectionNotDefinedException; use Drupal\Core\Language\Language; use Drupal\Core\Routing\CachedUrlGenerator; +use Drupal\Core\Routing\CachedUrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\UserSession; use Drupal\Core\StreamWrapper\PublicStream; @@ -3404,7 +3405,9 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv $generator->setRequest($request); // Ensure any internal caches of the URL generator are cleared. - $generator->clearCache(); + if ($generator instanceof CachedUrlGeneratorInterface) { + $generator->clearCache(); + } return $request; } diff --git a/core/modules/system/lib/Drupal/system/Form/RegionalForm.php b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php index f47a104..7a1e735 100644 --- a/core/modules/system/lib/Drupal/system/Form/RegionalForm.php +++ b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Locale\CountryManagerInterface; +use Drupal\Core\Routing\CachedUrlGeneratorInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\system\SystemConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -166,7 +167,9 @@ public function submitForm(array &$form, array &$form_state) { ->set('timezone.user.default', $form_state['values']['user_default_timezone']) ->save(); - $this->urlGenerator->clearCache(); + if ($this->urlGenerator instanceof CachedUrlGeneratorInterface) { + $this->urlGenerator->clearCache(); + } parent::submitForm($form, $form_state); }