Skip to content
Snippets Groups Projects
Commit 65d61cc7 authored by Angie Byron's avatar Angie Byron
Browse files

#761956 follow-up by bleen18: Fixed missing regions on Dashboard configuration page.

parent 67937250
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -310,18 +310,23 @@ function dashboard_admin_blocks() { ...@@ -310,18 +310,23 @@ function dashboard_admin_blocks() {
/** /**
* Implements hook_form_FORM_ID_alter(). * Implements hook_form_FORM_ID_alter().
*/ */
function dashboard_form_block_admin_display_form_alter(&$form, &$form_state) { function dashboard_form_block_admin_display_form_alter(&$form, &$form_state, $form_id) {
// Hide dashboard regions (and any blocks placed within them) from the block // Hide dashboard regions (and any blocks placed within them) from the block
// administration form and from the options list on that form. // administration form and from the options list on that form. This
$dashboard_regions = dashboard_region_descriptions(); // function is called for both the dashboard block configuration form and the
$form['block_regions']['#value'] = array_diff_key($form['block_regions']['#value'], $dashboard_regions); // standard block configuration form so that both forms can share the same
foreach (element_children($form['blocks']) as $i) { // constructor. As a result the form_id must be checked.
$block = &$form['blocks'][$i]; if ($form_id != 'dashboard_admin_display_form') {
if (isset($block['region']['#default_value']) && isset($dashboard_regions[$block['region']['#default_value']])) { $dashboard_regions = dashboard_region_descriptions();
$block['#access'] = FALSE; $form['block_regions']['#value'] = array_diff_key($form['block_regions']['#value'], $dashboard_regions);
} foreach (element_children($form['blocks']) as $i) {
elseif (isset($block['region']['#options'])) { $block = &$form['blocks'][$i];
$block['region']['#options'] = array_diff_key($block['region']['#options'], $dashboard_regions); if (isset($block['region']['#default_value']) && isset($dashboard_regions[$block['region']['#default_value']])) {
$block['#access'] = FALSE;
}
elseif (isset($block['region']['#options'])) {
$block['region']['#options'] = array_diff_key($block['region']['#options'], $dashboard_regions);
}
} }
} }
} }
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
* Tests for the dashboard module. * Tests for the dashboard module.
*/ */
class DashboardAccessTestCase extends DrupalWebTestCase { class DashboardBlocksTestCase extends DrupalWebTestCase {
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'Dashboard access', 'name' => 'Dashboard blocks',
'description' => 'Test access control for the dashboard.', 'description' => 'Test blocks as used by the dashboard.',
'group' => 'Dashboard', 'group' => 'Dashboard',
); );
} }
...@@ -57,4 +57,26 @@ class DashboardAccessTestCase extends DrupalWebTestCase { ...@@ -57,4 +57,26 @@ class DashboardAccessTestCase extends DrupalWebTestCase {
$this->assertResponse(403, t('Non-admin has no access to the dashboard.')); $this->assertResponse(403, t('Non-admin has no access to the dashboard.'));
$this->assertNoText($custom_block['title'], t('Non-admin has no access to a dashboard block.')); $this->assertNoText($custom_block['title'], t('Non-admin has no access to a dashboard block.'));
} }
/**
* Test that dashboard regions are displayed or hidden properly.
*/
function testDashboardRegions() {
$dashboard_regions = dashboard_region_descriptions();
// Ensure blocks can be placed in dashboard regions.
$this->drupalGet('admin/structure/dashboard');
foreach ($dashboard_regions as $region => $description) {
$elements = $this->xpath('//option[@value=:region]', array(':region' => $region));
$this->assertTrue(!empty($elements), t('%region is an available choice on the dashboard block configuration page.', array('%region' => $region)));
}
// Ensure blocks cannot be placed in dashboard regions on the standard
// blocks configuration page.
$this->drupalGet('admin/structure/block');
foreach ($dashboard_regions as $region => $description) {
$elements = $this->xpath('//option[@value=:region]', array(':region' => $region));
$this->assertTrue(empty($elements), t('%region is not an available choice on the block configuration page.', array('%region' => $region)));
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment