Commit d10c0519 authored by webchick's avatar webchick

Issue #1956448 by benjy, tim.plunkett, ed.hollinghurst, YesCT: Use the block...

Issue #1956448 by benjy, tim.plunkett, ed.hollinghurst, YesCT: Use the block instance title on the block admin listing.
parent 84693769
......@@ -58,6 +58,12 @@ a.block-demo-backlink:hover {
#block-placed {
background-color: #ffd;
}
#edit-settings-admin-label label {
display: inline;
}
#edit-settings-admin-label label:after {
content: ':';
}
/* Wide screens */
@media
......
......@@ -90,6 +90,11 @@ public function buildConfigurationForm(array $form, array &$form_state) {
'#value' => $definition['module'],
);
$form['admin_label'] = array(
'#type' => 'item',
'#title' => t('Block description'),
'#markup' => $definition['admin_label'],
);
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this->t('Title'),
......
......@@ -264,6 +264,9 @@ public function form(array $form, array &$form_state) {
'#prefix' => '<div id="edit-block-region-wrapper">',
'#suffix' => '</div>',
);
$form['#attached']['css'] = array(
drupal_get_path('module', 'block') . '/css/block.admin.css',
);
return $form;
}
......
......@@ -175,6 +175,7 @@ public function buildForm(array $form, array &$form_state) {
'#type' => 'table',
'#header' => array(
t('Block'),
t('Category'),
t('Region'),
t('Weight'),
t('Operations'),
......@@ -188,10 +189,11 @@ public function buildForm(array $form, array &$form_state) {
foreach ($entities as $entity_id => $entity) {
$definition = $entity->getPlugin()->getPluginDefinition();
$blocks[$entity->get('region')][$entity_id] = array(
'admin_label' => $definition['admin_label'],
'label' => $entity->label(),
'entity_id' => $entity_id,
'weight' => $entity->get('weight'),
'entity' => $entity,
'category' => $definition['category'],
);
}
......@@ -255,16 +257,19 @@ public function buildForm(array $form, array &$form_state) {
}
$form['blocks'][$entity_id]['info'] = array(
'#markup' => check_plain($info['admin_label']),
'#markup' => String::checkPlain($info['label']),
'#wrapper_attributes' => array(
'class' => array('block'),
),
);
$form['blocks'][$entity_id]['type'] = array(
'#markup' => $info['category'],
);
$form['blocks'][$entity_id]['region-theme']['region'] = array(
'#type' => 'select',
'#default_value' => $region,
'#empty_value' => BlockInterface::BLOCK_REGION_NONE,
'#title' => t('Region for @block block', array('@block' => $info['admin_label'])),
'#title' => t('Region for @block block', array('@block' => $info['label'])),
'#title_display' => 'invisible',
'#options' => $this->regions,
'#attributes' => array(
......@@ -281,7 +286,7 @@ public function buildForm(array $form, array &$form_state) {
'#type' => 'weight',
'#default_value' => $info['weight'],
'#delta' => $weight_delta,
'#title' => t('Weight for @block block', array('@block' => $info['admin_label'])),
'#title' => t('Weight for @block block', array('@block' => $info['label'])),
'#title_display' => 'invisible',
'#attributes' => array(
'class' => array('block-weight', 'block-weight-' . $region),
......
......@@ -58,12 +58,18 @@ public function testBlockInterface() {
$display_block->setConfigurationValue('display_message', 'My custom display message.');
$expected_configuration['display_message'] = 'My custom display message.';
$this->assertIdentical($display_block->getConfiguration(), $expected_configuration, 'The block configuration was updated correctly.');
$definition = $display_block->getPluginDefinition();
$expected_form = array(
'module' => array(
'#type' => 'value',
'#value' => 'block_test',
),
'admin_label' => array(
'#type' => 'item',
'#title' => t('Block description'),
'#markup' => $definition['admin_label'],
),
'label' => array(
'#type' => 'textfield',
'#title' => 'Title',
......
......@@ -23,6 +23,20 @@ class BlockUiTest extends WebTestBase {
protected $regions;
/**
* The submitted block values used by this test.
*
* @var array
*/
protected $blockValues;
/**
* The block entities used by this test.
*
* @var \Drupal\block\BlockInterface[]
*/
protected $blocks;
/**
* An administrative user to configure the test environment.
*/
......@@ -46,7 +60,7 @@ function setUp() {
$this->drupalLogin($this->adminUser);
// Enable some test blocks.
$this->testBlocks = array(
$this->blockValues = array(
array(
'label' => 'Tools',
'tr' => '5',
......@@ -62,8 +76,9 @@ function setUp() {
'test_weight' => '0',
),
);
foreach ($this->testBlocks as $values) {
$this->drupalPlaceBlock($values['plugin_id'], $values['settings']);
$this->blocks = array();
foreach ($this->blockValues as $values) {
$this->blocks[] = $this->drupalPlaceBlock($values['plugin_id'], $values['settings']);
}
}
......@@ -88,9 +103,11 @@ function testBlockAdminUiPage() {
$blocks_table = $this->xpath("//table[@id='blocks']");
$this->assertTrue(!empty($blocks_table), 'The blocks table is being rendered.');
// Look for test blocks in the table.
foreach ($this->testBlocks as $values) {
foreach ($this->blockValues as $delta => $values) {
$block = $this->blocks[$delta];
$label = $block->label();
$element = $this->xpath('//*[@id="blocks"]/tbody/tr[' . $values['tr'] . ']/td[1]/text()');
$this->assertTrue((string)$element[0] == $values['label'], 'The "' . $values['label'] . '" block title is set inside the ' . $values['settings']['region'] . ' region.');
$this->assertTrue((string) $element[0] == $label, 'The "' . $label . '" block title is set inside the ' . $values['settings']['region'] . ' region.');
// Look for a test block region select form element.
$this->assertField('blocks[' . $values['settings']['id'] . '][region]', 'The block "' . $values['label'] . '" has a region assignment field.');
// Move the test block to the header region.
......@@ -101,17 +118,17 @@ function testBlockAdminUiPage() {
$edit['blocks[' . $values['settings']['id'] . '][weight]'] = $values['test_weight'];
}
$this->drupalPostForm('admin/structure/block', $edit, t('Save blocks'));
foreach ($this->testBlocks as $values) {
foreach ($this->blockValues as $values) {
// Check if the region and weight settings changes have persisted.
$this->assertOptionSelected(
'edit-blocks-' . $values['settings']['id'] . '-region',
'header',
'The block "' . $values['label'] . '" has the correct region assignment (header).'
'The block "' . $label . '" has the correct region assignment (header).'
);
$this->assertOptionSelected(
'edit-blocks-' . $values['settings']['id'] . '-weight',
$values['test_weight'],
'The block "' . $values['label'] . '" has the correct weight assignment (' . $values['test_weight'] . ').'
'The block "' . $label . '" has the correct weight assignment (' . $values['test_weight'] . ').'
);
}
}
......
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