diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php index 078c8eed075071d5b5ec1f96f1cd06fcc33426c9..ab2cbca91db17b890c2cf65a142fdfeb8534a1a1 100644 --- a/core/lib/Drupal/Core/Access/AccessResult.php +++ b/core/lib/Drupal/Core/Access/AccessResult.php @@ -301,10 +301,11 @@ public function cacheUntilEntityChanges(EntityInterface $entity) { * * @return $this * - * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use - * ::addCacheableDependency() instead. + * @deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use + * \Drupal\Core\Access\AccessResult::addCacheableDependency() instead. */ public function cacheUntilConfigurationChanges(ConfigBase $configuration) { + @trigger_error(__METHOD__ . ' is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Access\AccessResult::addCacheableDependency() instead.', E_USER_DEPRECATED); return $this->addCacheableDependency($configuration); } diff --git a/core/modules/contact/src/Access/ContactPageAccess.php b/core/modules/contact/src/Access/ContactPageAccess.php index 2038357962719eaa452217f82dd5a4b129d14787..137fea1550f033a64f979dc8589a13e4df9ca20d 100644 --- a/core/modules/contact/src/Access/ContactPageAccess.php +++ b/core/modules/contact/src/Access/ContactPageAccess.php @@ -88,7 +88,7 @@ public function access(UserInterface $user, AccountInterface $account) { // If the requested user did not save a preference yet, deny access if the // configured default is disabled. $contact_settings = $this->configFactory->get('contact.settings'); - $access->cacheUntilConfigurationChanges($contact_settings); + $access->addCacheableDependency($contact_settings); if (!isset($account_data) && !$contact_settings->get('user_default_enabled')) { return $access; } diff --git a/core/modules/user/src/Access/RegisterAccessCheck.php b/core/modules/user/src/Access/RegisterAccessCheck.php index 01075b8c9c0d9d4f9bbb095292ab7109c46d52c3..585440e0681b29a30e36d141d5602ea6b80a0f40 100644 --- a/core/modules/user/src/Access/RegisterAccessCheck.php +++ b/core/modules/user/src/Access/RegisterAccessCheck.php @@ -23,7 +23,7 @@ class RegisterAccessCheck implements AccessInterface { */ public function access(AccountInterface $account) { $user_settings = \Drupal::config('user.settings'); - return AccessResult::allowedIf($account->isAnonymous() && $user_settings->get('register') != UserInterface::REGISTER_ADMINISTRATORS_ONLY)->cacheUntilConfigurationChanges($user_settings); + return AccessResult::allowedIf($account->isAnonymous() && $user_settings->get('register') != UserInterface::REGISTER_ADMINISTRATORS_ONLY)->addCacheableDependency($user_settings); } } diff --git a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php index 0efca8eb63a60241e0b6c6ce33c252275380c8c8..9e761a50dc5ebca64028ef066c9586da0d00a56d 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php @@ -13,6 +13,7 @@ use Drupal\Core\Access\AccessResultReasonInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheableDependencyInterface; +use Drupal\Core\Config\Config; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Tests\UnitTestCase; @@ -968,6 +969,21 @@ public function providerTestAllowedIfHasPermissions() { return $data; } + /** + * @expectedDeprecation Drupal\Core\Access\AccessResult::cacheUntilConfigurationChanges is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Access\AccessResult::addCacheableDependency() instead. + * @group legacy + */ + public function testCacheUntilConfigurationChanges() { + $config = $this->prophesize(Config::class); + $config->getCacheContexts()->willReturn(['context']); + $config->getCacheTags()->willReturn(['tag']); + $config->getCacheMaxAge()->willReturn(10); + $access_result = AccessResult::neutral()->cacheUntilConfigurationChanges($config->reveal()); + $this->assertSame(['context'], $access_result->getCacheContexts()); + $this->assertSame(['tag'], $access_result->getCacheTags()); + $this->assertSame(10, $access_result->getCacheMaxAge()); + } + } class UncacheableTestAccessResult implements AccessResultInterface {