Commit c231009d authored by webchick's avatar webchick

Issue #1875260 by Gábor Hojtsy, xjm, brantwynn, EclipseGc, Bojhan: Fixed Make...

Issue #1875260 by Gábor Hojtsy, xjm, brantwynn, EclipseGc, Bojhan: Fixed Make the block title required and allow it to be hidden.
parent c07e727d
......@@ -42,6 +42,11 @@
*/
const BLOCK_VISIBILITY_PHP = 2;
/**
* Indicates the block label (title) should be displayed to end users.
*/
const BLOCK_LABEL_VISIBLE = 'visible';
/**
* Implements hook_help().
*/
......@@ -528,6 +533,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])) {
......
......@@ -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 == BLOCK_LABEL_VISIBLE ? TRUE : FALSE,
'#return_value' => BLOCK_LABEL_VISIBLE,
);
$form['machine_name'] = array(
'#type' => 'machine_name',
......
......@@ -52,6 +52,17 @@ class Block extends ConfigEntityBase {
*/
public $label;
/**
* Whether the block label is displayed to end users.
*
* When this is set to BLOCK_LABEL_VISIBLE (the default value), the label is
* rendered as header in the block markup. Otherwise, the label is passed
* to the block template as a separate $label_hidden variable.
*
* @var string
*/
public $label_display = BLOCK_LABEL_VISIBLE;
/**
* The block UUID.
*
......@@ -169,6 +180,7 @@ public function getExportProperties() {
$names = array(
'id',
'label',
'label_display',
'uuid',
'region',
'weight',
......
......@@ -93,6 +93,7 @@ protected function createTests() {
$expected_properties = array(
'id' => 'stark.test_block',
'label' => '',
'label_display' => BLOCK_LABEL_VISIBLE,
'region' => '-1',
'weight' => '',
'module' => 'block_test',
......
......@@ -313,6 +313,37 @@ function testBlock() {
$this->assertNoFieldByXPath($xpath, FALSE, 'Block found in no regions.');
}
/**
* 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.
*
......
......@@ -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.
......
......@@ -16,3 +16,4 @@ visibility:
plugin: 'system_menu_block:menu-admin'
settings:
cache: '-1'
label_display: visible
......@@ -16,3 +16,4 @@ visibility:
plugin: user_login_block
settings:
cache: '-1'
label_display: visible
......@@ -16,3 +16,4 @@ visibility:
plugin: 'system_menu_block:menu-tools'
settings:
cache: '-1'
label_display: visible
......@@ -19,3 +19,4 @@ module: system
region: content
weight: '0'
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: system
region: footer
weight: '0'
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: system
region: help
weight: '0'
langcode: en
label_display: visible
......@@ -20,3 +20,4 @@ region: sidebar_first
weight: '0'
plugin: user_login_block
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: system
region: footer
weight: '10'
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: search
region: sidebar_first
weight: '-1'
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: system
region: sidebar_first
weight: '0'
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: system
region: content
weight: '0'
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: system
region: help
weight: '0'
langcode: en
label_display: visible
......@@ -19,3 +19,4 @@ module: user
region: content
weight: '10'
langcode: en
label_display: visible
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment