core/lib/Drupal/Core/Cache/CacheBackendInterface.php | 2 +- core/modules/block/lib/Drupal/block/BlockBase.php | 2 +- core/modules/block/lib/Drupal/block/BlockViewBuilder.php | 3 ++- core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php index 3bdbc64..36fd5a3 100644 --- a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php @@ -74,7 +74,7 @@ /** * Indicates that the item should never be removed unless explicitly deleted. */ - const CACHE_PERMANENT = 0; + const CACHE_PERMANENT = -1; /** * Returns data from the persistent cache. diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index 5b7986c..8185a18 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -115,7 +115,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { ); $ages = array(0, 60, 300, 1800, 3600, 21600, 86400, 604800, 2592000, 31536000); $options = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($ages, $ages)); - $options[-1] = t('Forever'); + $options[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever'); $form['cache']['max_age'] = array( '#type' => 'select', '#title' => t('Cache: Max age'), diff --git a/core/modules/block/lib/Drupal/block/BlockViewBuilder.php b/core/modules/block/lib/Drupal/block/BlockViewBuilder.php index d6e5056..6fe8abc 100644 --- a/core/modules/block/lib/Drupal/block/BlockViewBuilder.php +++ b/core/modules/block/lib/Drupal/block/BlockViewBuilder.php @@ -83,10 +83,11 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la // Generic cache keys, with the block plugin's custom keys appended // (usually cache context keys like DRUPAL_CACHE_PER_ROLE). $default_cache_keys = array('entity_view', 'block', $entity->id(), $entity->langcode); + $max_age = $plugin->getCacheMaxAge(); $build[$entity_id]['#cache'] += array( 'keys' => array_merge($default_cache_keys, $plugin->getCacheKeys()), 'bin' => $plugin->getCacheBin(), - 'expire' => REQUEST_TIME + $plugin->getCacheMaxAge(), + 'expire' => ($max_age === Cache::PERMANENT) ? Cache::PERMANENT : REQUEST_TIME + $max_age, ); } else { diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php index 628a7bf..f9c0921 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockInterfaceTest.php @@ -64,7 +64,7 @@ public function testBlockInterface() { $ages = array(0, 60, 300, 1800, 3600, 21600, 86400, 604800, 2592000, 31536000); $options = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($ages, $ages)); - $options[-1] = t('Forever'); + $options[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever'); $expected_form = array( 'module' => array( '#type' => 'value',