From f95b1e85fb46d8022f4517b42c55b02509fd7f6f Mon Sep 17 00:00:00 2001 From: Neill Magill <neill.magill@nottingham.ac.uk> Date: Mon, 19 Jan 2015 15:45:44 +0000 Subject: [PATCH] MDL-48865 core_block: Show regions with only hidden blocks when editing Before this patch if all the blocks in a block region are set to hidden the region will be docked even when editing is enabled. This meant that as a user I would need to add a new block to the page and move it to that region via the configuration menu before I could manipulate the hidden blocks again. --- .../tests/behat/hidden_block_region.feature | 49 +++++++++++++++++++ lib/blocklib.php | 5 ++ 2 files changed, 54 insertions(+) create mode 100644 blocks/tests/behat/hidden_block_region.feature diff --git a/blocks/tests/behat/hidden_block_region.feature b/blocks/tests/behat/hidden_block_region.feature new file mode 100644 index 00000000000..f08b3494c3c --- /dev/null +++ b/blocks/tests/behat/hidden_block_region.feature @@ -0,0 +1,49 @@ +@core @core_block +Feature: Show hidden blocks in a docked block region when editing + In order to edit blocks in a hidden region + As a teacher + I need to be able to see the blocks when editing is on + + Background: + Given the following "courses" exist: + | fullname | shortname | format | + | Course 1 | C1 | topics | + And the following "course enrolments" exist: + | user | course | role | + | admin | C1 | editingteacher | + And I log in as "admin" + And I follow "Course 1" + And I turn editing mode on + # Hide all the blocks in the non-default region + And I configure the "Search forums" block + And I set the following fields to these values: + | Visible | No | + And I click on "Save changes" "button" + And I configure the "Latest news" block + And I set the following fields to these values: + | Visible | No | + And I click on "Save changes" "button" + And I configure the "Upcoming events" block + And I set the following fields to these values: + | Visible | No | + And I click on "Save changes" "button" + And I configure the "Recent activity" block + And I set the following fields to these values: + | Visible | No | + When I click on "Save changes" "button" + # Editing is on so they should be visible + Then I should see "Search forums" + And I should see "Latest news" + And I should see "Upcoming events" + And I should see "Recent activity" + And I turn editing mode off + # Editing is off, so they should no longer be visible + And I should not see "Search forums" + And I should not see "Latest news" + And I should not see "Upcoming events" + And I should not see "Recent activity" + + @javascript + Scenario: Check that a region with only hidden blocks is not docked in editing mode (javascript enabled) + + Scenario: Check that a region with only hidden blocks is not docked in editing mode (javascript disabled) diff --git a/lib/blocklib.php b/lib/blocklib.php index f75455aa3c4..76936c6c908 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -486,6 +486,11 @@ class block_manager { return false; } + // Block regions should not be docked during editing when all the blocks are hidden. + if ($this->page->user_is_editing() && $this->page->user_can_edit_blocks()) { + return false; + } + $this->check_is_loaded(); $this->ensure_content_created($region, $output); if (!$this->region_has_content($region, $output)) {