diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 3e3c4af..667272b 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -528,6 +528,11 @@ function template_preprocess_block(&$variables) { $block_counter = &drupal_static(__FUNCTION__, array()); $variables['block'] = (object) $variables['elements']['#block_config']; + // If the block title is configured to be hidden, set it to an empty string. + if (empty($variables['elements']['#block']->label_display)) { + $variables['block']->label_hidden = $variables['block']->label; + $variables['block']->label = ''; + } // All blocks get an independent counter for each region. if (!isset($block_counter[$variables['block']->region])) { diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index d32444f..8e72b6b 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -238,6 +238,13 @@ public function form($form, &$form_state) { '#title' => t('Title'), '#maxlength' => 255, '#default_value' => !$entity->isNew() ? $entity->label() : $definition['admin_label'], + '#required' => TRUE, + ); + $form['label_display'] = array( + '#type' => 'checkbox', + '#title' => t('Display title'), + '#default_value' => $entity->label_display == 'visible' ? TRUE : FALSE, + '#return_value' => 'visible', ); $form['machine_name'] = array( '#type' => 'machine_name', diff --git a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php index 75d82e8..df74086 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php @@ -53,6 +53,13 @@ class Block extends ConfigEntityBase { public $label; /** + * The label is displayed by default. + * + * @var string + */ + public $label_display = 'visible'; + + /** * The block UUID. * * @var string @@ -169,6 +176,7 @@ public function getExportProperties() { $names = array( 'id', 'label', + 'label_display', 'uuid', 'region', 'weight', diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index ec4e7cd..20a2228 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -93,6 +93,7 @@ protected function createTests() { $expected_properties = array( 'id' => 'stark.test_block', 'label' => '', + 'label_display' => 'visible', 'region' => '-1', 'weight' => '', 'module' => 'block_test', diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index e9c5f18..1c70282 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -314,6 +314,37 @@ function testBlock() { } /** + * Test block title display settings. + */ + function testHideBlockTitle() { + $block_name = 'system_powered_by_block'; + // Create a random title for the block. + $title = $this->randomName(8); + $machine_name = strtolower($this->randomName(8)); + // Enable a standard block. + $default_theme = variable_get('theme_default', 'stark'); + $edit = array( + 'machine_name' => $machine_name, + 'region' => 'sidebar_first', + 'label' => $title, + ); + $this->drupalPost('admin/structure/block/add/' . $block_name . '/' . $default_theme, $edit, t('Save block')); + $this->assertText('The block configuration has been saved.', 'Block was saved'); + + $this->drupalGet('user'); + $this->assertText($title, 'Block title was displayed by default.'); + + $edit = array( + 'label_display' => FALSE, + ); + $this->drupalPost('admin/structure/block/manage/' . $default_theme . '.' . $machine_name . '/configure', $edit, t('Save block')); + $this->assertText('The block configuration has been saved.', 'Block was saved'); + + $this->drupalGet('user'); + $this->assertNoText($title, 'Block title was not displayed when hidden.'); + } + + /** * Moves a block to a given region via the UI and confirms the result. * * @param array $block diff --git a/core/modules/block/templates/block.tpl.php b/core/modules/block/templates/block.tpl.php index 16ced60..00b554a 100644 --- a/core/modules/block/templates/block.tpl.php +++ b/core/modules/block/templates/block.tpl.php @@ -6,6 +6,8 @@ * * Available variables: * - $block->label: Block title. + * - $block->label_hidden: The hidden block title value if the block was + * configured to hide the title ($block->label is empty in this case). * - $content: Block content. * - $block->module: Module that generated the block. * - $block->delta: An ID for the block, unique within each module. diff --git a/core/profiles/minimal/config/block.block.stark.admin.yml b/core/profiles/minimal/config/block.block.stark.admin.yml index 5f62f7d..e84cdbe 100644 --- a/core/profiles/minimal/config/block.block.stark.admin.yml +++ b/core/profiles/minimal/config/block.block.stark.admin.yml @@ -16,3 +16,4 @@ visibility: plugin: 'system_menu_block:menu-admin' settings: cache: '-1' +label_display: visible diff --git a/core/profiles/minimal/config/block.block.stark.login.yml b/core/profiles/minimal/config/block.block.stark.login.yml index 6154106..ba8a66d 100644 --- a/core/profiles/minimal/config/block.block.stark.login.yml +++ b/core/profiles/minimal/config/block.block.stark.login.yml @@ -16,3 +16,4 @@ visibility: plugin: user_login_block settings: cache: '-1' +label_display: visible diff --git a/core/profiles/minimal/config/block.block.stark.tools.yml b/core/profiles/minimal/config/block.block.stark.tools.yml index 4942f50..dda5b98 100644 --- a/core/profiles/minimal/config/block.block.stark.tools.yml +++ b/core/profiles/minimal/config/block.block.stark.tools.yml @@ -16,3 +16,4 @@ visibility: plugin: 'system_menu_block:menu-tools' settings: cache: '-1' +label_display: visible diff --git a/core/profiles/standard/config/block.block.bartik.content.yml b/core/profiles/standard/config/block.block.bartik.content.yml index fd53c61..07c3cdd 100644 --- a/core/profiles/standard/config/block.block.bartik.content.yml +++ b/core/profiles/standard/config/block.block.bartik.content.yml @@ -19,3 +19,4 @@ module: system region: content weight: '0' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.bartik.footer.yml b/core/profiles/standard/config/block.block.bartik.footer.yml index 194a598..553edb7 100644 --- a/core/profiles/standard/config/block.block.bartik.footer.yml +++ b/core/profiles/standard/config/block.block.bartik.footer.yml @@ -19,3 +19,4 @@ module: system region: footer weight: '0' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.bartik.help.yml b/core/profiles/standard/config/block.block.bartik.help.yml index 89814c9..84395a6 100644 --- a/core/profiles/standard/config/block.block.bartik.help.yml +++ b/core/profiles/standard/config/block.block.bartik.help.yml @@ -19,3 +19,4 @@ module: system region: help weight: '0' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.bartik.login.yml b/core/profiles/standard/config/block.block.bartik.login.yml index 8bb0bbd..aac6997 100644 --- a/core/profiles/standard/config/block.block.bartik.login.yml +++ b/core/profiles/standard/config/block.block.bartik.login.yml @@ -20,3 +20,4 @@ region: sidebar_first weight: '0' plugin: user_login_block langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.bartik.powered.yml b/core/profiles/standard/config/block.block.bartik.powered.yml index 9c54359..48424f8 100644 --- a/core/profiles/standard/config/block.block.bartik.powered.yml +++ b/core/profiles/standard/config/block.block.bartik.powered.yml @@ -19,3 +19,4 @@ module: system region: footer weight: '10' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.bartik.search.yml b/core/profiles/standard/config/block.block.bartik.search.yml index bd43d51..bcf0249 100644 --- a/core/profiles/standard/config/block.block.bartik.search.yml +++ b/core/profiles/standard/config/block.block.bartik.search.yml @@ -19,3 +19,4 @@ module: search region: sidebar_first weight: '-1' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.bartik.tools.yml b/core/profiles/standard/config/block.block.bartik.tools.yml index ff2c634..56c8ba4 100644 --- a/core/profiles/standard/config/block.block.bartik.tools.yml +++ b/core/profiles/standard/config/block.block.bartik.tools.yml @@ -19,3 +19,4 @@ module: system region: sidebar_first weight: '0' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.seven.content.yml b/core/profiles/standard/config/block.block.seven.content.yml index 11f76a9..f14f147 100644 --- a/core/profiles/standard/config/block.block.seven.content.yml +++ b/core/profiles/standard/config/block.block.seven.content.yml @@ -19,3 +19,4 @@ module: system region: content weight: '0' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.seven.help.yml b/core/profiles/standard/config/block.block.seven.help.yml index 9a29775..075f518 100644 --- a/core/profiles/standard/config/block.block.seven.help.yml +++ b/core/profiles/standard/config/block.block.seven.help.yml @@ -19,3 +19,4 @@ module: system region: help weight: '0' langcode: en +label_display: visible diff --git a/core/profiles/standard/config/block.block.seven.login.yml b/core/profiles/standard/config/block.block.seven.login.yml index 8e89cd0..f0fb2b2 100644 --- a/core/profiles/standard/config/block.block.seven.login.yml +++ b/core/profiles/standard/config/block.block.seven.login.yml @@ -19,3 +19,4 @@ module: user region: content weight: '10' langcode: en +label_display: visible