From 6c183523d0d817cfe3d1ce93d96e5e2865183cfb Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 25 Jul 2019 08:50:28 +0100
Subject: [PATCH] Issue #3069028 by alexpott: Properly Deprecate
 Drupal\Core\Access\AccessResult::cacheUntilConfigurationChanges

---
 core/lib/Drupal/Core/Access/AccessResult.php     |  5 +++--
 .../contact/src/Access/ContactPageAccess.php     |  2 +-
 .../user/src/Access/RegisterAccessCheck.php      |  2 +-
 .../Tests/Core/Access/AccessResultTest.php       | 16 ++++++++++++++++
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/core/lib/Drupal/Core/Access/AccessResult.php b/core/lib/Drupal/Core/Access/AccessResult.php
index 078c8eed0750..ab2cbca91db1 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 203835796271..137fea1550f0 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 01075b8c9c0d..585440e0681b 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 0efca8eb63a6..9e761a50dc5e 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 {
-- 
GitLab