diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 3d4f3a0..99980cc 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -295,13 +295,6 @@ block_settings: label_display: type: string label: 'Display title' - cache: - type: mapping - label: 'Cache settings' - mapping: - max_age: - type: integer - label: 'Maximum age' status: type: boolean label: 'Status' diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index 8c97809..db2cd94 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -89,10 +89,6 @@ protected function baseConfigurationDefaults() { 'label' => '', 'provider' => $this->pluginDefinition['provider'], 'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE, - 'cache' => array( - // Blocks are cacheable by default. - 'max_age' => Cache::PERMANENT, - ), ); } @@ -180,23 +176,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => ($this->configuration['label_display'] === BlockInterface::BLOCK_LABEL_VISIBLE), '#return_value' => BlockInterface::BLOCK_LABEL_VISIBLE, ); - // Identical options to the ones for page caching. - // @see \Drupal\system\Form\PerformanceForm::buildForm() - $period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400); - $period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($period, $period)); - $period[0] = '<' . $this->t('no caching') . '>'; - $period[\Drupal\Core\Cache\Cache::PERMANENT] = $this->t('Forever'); - $form['cache'] = array( - '#type' => 'details', - '#title' => $this->t('Cache settings'), - ); - $form['cache']['max_age'] = array( - '#type' => 'select', - '#title' => $this->t('Maximum age'), - '#description' => $this->t('The maximum time this block may be cached.'), - '#default_value' => $this->configuration['cache']['max_age'], - '#options' => $period, - ); // Add plugin-specific settings for this block type. $form += $this->blockForm($form, $form_state); @@ -244,7 +223,6 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s $this->configuration['label'] = $form_state->getValue('label'); $this->configuration['label_display'] = $form_state->getValue('label_display'); $this->configuration['provider'] = $form_state->getValue('provider'); - $this->configuration['cache'] = $form_state->getValue('cache'); $this->blockSubmit($form, $form_state); } } @@ -273,16 +251,6 @@ public function getMachineNameSuggestion() { } /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - $max_age = parent::getCacheMaxAge(); - // @todo Configurability of this will be removed in - // https://www.drupal.org/node/2458763. - return Cache::mergeMaxAges($max_age, (int) $this->configuration['cache']['max_age']); - } - - /** * Wraps the transliteration service. * * @return \Drupal\Component\Transliteration\TransliterationInterface diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 8c13bbb..0397270 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -182,6 +182,7 @@ public function form(array $form, FormStateInterface $form_state) { '#prefix' => '
', '#suffix' => '
', ); + $form['#attached']['library'][] = 'block/drupal.block.admin'; return $form; } diff --git a/core/modules/block/src/Tests/BlockCacheTest.php b/core/modules/block/src/Tests/BlockCacheTest.php index b118e84..856dbb4 100644 --- a/core/modules/block/src/Tests/BlockCacheTest.php +++ b/core/modules/block/src/Tests/BlockCacheTest.php @@ -148,9 +148,7 @@ function testCachePermissions() { * Test non-cacheable block. */ function testNoCache() { - $this->setBlockCacheConfig(array( - 'max_age' => 0, - )); + \Drupal::state()->set('block_test.cache_max_age', 0); $current_content = $this->randomMachineName(); \Drupal::state()->set('block_test.content', $current_content); @@ -219,13 +217,4 @@ function testCachePerPage() { $this->assertText($old_content, 'Block content cached for the test page.'); } - /** - * Private helper method to set the test block's cache configuration. - */ - private function setBlockCacheConfig($cache_config) { - $block = $this->block->getPlugin(); - $block->setConfigurationValue('cache', $cache_config); - $this->block->save(); - } - } diff --git a/core/modules/block/src/Tests/BlockInterfaceTest.php b/core/modules/block/src/Tests/BlockInterfaceTest.php index 7215765..2e172a0 100644 --- a/core/modules/block/src/Tests/BlockInterfaceTest.php +++ b/core/modules/block/src/Tests/BlockInterfaceTest.php @@ -7,7 +7,6 @@ namespace Drupal\block\Tests; -use Drupal\Core\Cache\Cache; use Drupal\Core\Form\FormState; use Drupal\simpletest\KernelTestBase; use Drupal\block\BlockInterface; @@ -44,9 +43,6 @@ public function testBlockInterface() { 'label' => 'Custom Display Message', 'provider' => 'block_test', 'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE, - 'cache' => array( - 'max_age' => Cache::PERMANENT, - ), 'display_message' => 'no message set', ); // Initial configuration of the block at construction time. @@ -60,10 +56,6 @@ public function testBlockInterface() { $this->assertIdentical($display_block->getConfiguration(), $expected_configuration, 'The block configuration was updated correctly.'); $definition = $display_block->getPluginDefinition(); - $period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400); - $period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($period, $period)); - $period[0] = '<' . t('no caching') . '>'; - $period[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever'); $expected_form = array( 'provider' => array( '#type' => 'value', @@ -87,17 +79,6 @@ public function testBlockInterface() { '#default_value' => TRUE, '#return_value' => 'visible', ), - 'cache' => array( - '#type' => 'details', - '#title' => t('Cache settings'), - 'max_age' => array( - '#type' => 'select', - '#title' => t('Maximum age'), - '#description' => t('The maximum time this block may be cached.'), - '#default_value' => Cache::PERMANENT, - '#options' => $period, - ), - ), 'display_message' => array( '#type' => 'textfield', '#title' => t('Display message'), diff --git a/core/modules/block/src/Tests/BlockStorageUnitTest.php b/core/modules/block/src/Tests/BlockStorageUnitTest.php index f1d435a..140f746 100644 --- a/core/modules/block/src/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/src/Tests/BlockStorageUnitTest.php @@ -7,7 +7,6 @@ namespace Drupal\block\Tests; -use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityStorage; use Drupal\simpletest\KernelTestBase; use Drupal\block_test\Plugin\Block\TestHtmlBlock; @@ -99,9 +98,6 @@ protected function createTests() { 'label' => '', 'provider' => 'block_test', 'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE, - 'cache' => array( - 'max_age' => Cache::PERMANENT, - ), ), 'visibility' => array(), ); diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php index abe4cc7..157acb4 100644 --- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php +++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php @@ -8,6 +8,7 @@ namespace Drupal\block_test\Plugin\Block; use Drupal\Core\Block\BlockBase; +use Drupal\Core\Cache\Cache; /** * Provides a block to test caching. @@ -39,4 +40,11 @@ public function getCacheContexts() { return \Drupal::state()->get('block_test.cache_contexts', []); } + /** + * {@inheritdoc} + */ + public function getCacheMaxAge() { + return \Drupal::state()->get('block_test.cache_max_age', parent::getCacheMaxAge()); + } + } diff --git a/core/modules/node/src/Plugin/Block/SyndicateBlock.php b/core/modules/node/src/Plugin/Block/SyndicateBlock.php index 9e5834b..1e40332 100644 --- a/core/modules/node/src/Plugin/Block/SyndicateBlock.php +++ b/core/modules/node/src/Plugin/Block/SyndicateBlock.php @@ -50,27 +50,4 @@ public function build() { ); } - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - - // @see ::getCacheMaxAge() - $form['cache']['#disabled'] = TRUE; - $form['cache']['max_age']['#value'] = Cache::PERMANENT; - $form['cache']['#description'] = $this->t('This block is always cached forever, it is not configurable.'); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - // The 'Syndicate' block is permanently cacheable, because its - // contents can never change. - return Cache::PERMANENT; - } - } diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 905fb3e..e9dc6f7 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -408,7 +408,6 @@ protected function drupalBuildEntityView(EntityInterface $entity, $view_mode = ' * - region: 'sidebar_first'. * - theme: The default theme. * - visibility: Empty array. - * - cache: array('max_age' => Cache::PERMANENT). * * @return \Drupal\block\Entity\Block * The block entity. @@ -425,9 +424,6 @@ protected function drupalPlaceBlock($plugin_id, array $settings = array()) { 'label' => $this->randomMachineName(8), 'visibility' => array(), 'weight' => 0, - 'cache' => array( - 'max_age' => Cache::PERMANENT, - ), ); $values = []; foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) { diff --git a/core/modules/system/src/Plugin/Block/SystemMainBlock.php b/core/modules/system/src/Plugin/Block/SystemMainBlock.php index f164f66..92475ab 100644 --- a/core/modules/system/src/Plugin/Block/SystemMainBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMainBlock.php @@ -43,17 +43,4 @@ public function build() { return $this->mainContent; } - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - - $form['cache']['#disabled'] = TRUE; - $form['cache']['#description'] = $this->t("This block's maximum age cannot be configured, because it depends on the contents."); - $form['cache']['max_age']['#value'] = Cache::PERMANENT; - - return $form; - } - } diff --git a/core/modules/system/src/Plugin/Block/SystemMessagesBlock.php b/core/modules/system/src/Plugin/Block/SystemMessagesBlock.php index 11f312a..c1d78fb 100644 --- a/core/modules/system/src/Plugin/Block/SystemMessagesBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMessagesBlock.php @@ -43,20 +43,6 @@ public function build() { /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - - // @see ::getCacheMaxAge() - $form['cache']['#description'] = $this->t('This block is cacheable forever, it is not configurable.'); - $form['cache']['max_age']['#value'] = Cache::PERMANENT; - $form['cache']['max_age']['#disabled'] = TRUE; - - return $form; - } - - /** - * {@inheritdoc} - */ public function getCacheMaxAge() { // The messages are session-specific and hence aren't cacheable, but the // block itself *is* cacheable because it uses a #lazy_builder callback and diff --git a/core/modules/system/src/Plugin/Block/SystemPoweredByBlock.php b/core/modules/system/src/Plugin/Block/SystemPoweredByBlock.php index c768e21..b9adca8 100644 --- a/core/modules/system/src/Plugin/Block/SystemPoweredByBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemPoweredByBlock.php @@ -28,27 +28,4 @@ public function build() { return array('#markup' => '' . $this->t('Powered by Drupal', array('@poweredby' => 'https://www.drupal.org')) . ''); } - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - - // @see ::getCacheMaxAge() - $form['cache']['#disabled'] = TRUE; - $form['cache']['max_age']['#value'] = Cache::PERMANENT; - $form['cache']['#description'] = $this->t('This block is always cached forever, it is not configurable.'); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - // The 'Powered by Drupal' block is permanently cacheable, because its - // contents can never change. - return Cache::PERMANENT; - } - } diff --git a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php index d79e4eb..06c8732 100644 --- a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php +++ b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\BlockBase; +use Drupal\Core\Cache\Cache; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\views\ViewExecutableFactory; diff --git a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php index 4d08d3a..71e278f 100644 --- a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php +++ b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php @@ -7,7 +7,6 @@ namespace Drupal\views\Tests\Plugin; -use Drupal\Core\Cache\Cache; use Drupal\views\Tests\ViewKernelTestBase; /** @@ -83,7 +82,6 @@ public function testViewsBlock() { * - region: 'sidebar_first'. * - theme: The default theme. * - visibility: Empty array. - * - cache: array('max_age' => Cache::PERMANENT). * * @return \Drupal\block\Entity\Block * The block entity. @@ -97,9 +95,6 @@ protected function createBlock($plugin_id, array $settings = array()) { 'label' => $this->randomMachineName(8), 'visibility' => array(), 'weight' => 0, - 'cache' => array( - 'max_age' => Cache::PERMANENT, - ), ); $values = []; foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) {