-
Improvement
-
Resolution: Fixed
-
Minor
-
3.7.2, 3.10
-
MOODLE_310_STABLE, MOODLE_37_STABLE
-
MOODLE_310_STABLE
-
MDL-64818_master -
- Login.
- Confirm Block titles are as expected.
- Turn editing on and confirm that blocks can be moved around as expected.
In 'lib/outputrenderers.php' within the 'core_renderer' class there is the method 'blocks_for_region'. It currently has the code of:
public function blocks_for_region($region) { |
$blockcontents = $this->page->blocks->get_content_for_region($region, $this); |
$blocks = $this->page->blocks->get_blocks_for_region($region); |
$lastblock = null; |
$zones = array();
|
foreach ($blocks as $block) {
|
$zones[] = $block->title;
|
}
|
$output = ''; |
foreach ($blockcontents as $bc) {
|
if ($bc instanceof block_contents) { |
$output .= $this->block($bc, $region); |
$lastblock = $bc->title;
|
} else if ($bc instanceof block_move_target) { |
$output .= $this->block_move_target($bc, $zones, $lastblock, $region); |
} else { |
throw new coding_exception('Unexpected type of thing (' . get_class($bc) . ') found in list of block contents.'); |
}
|
}
|
return $output; |
}
|
where the '$zones' array is the only thing that needs the contents of the humongous '$blocks' array of objects just for the block title, which as it happens is identical to the 'title' attribute contained within the 'block_contents' instances returned by the 'get_content_for_region' call to produce '$blockcontents'. Thus, changing the code to:
public function blocks_for_region($region) { |
$blockcontents = $this->page->blocks->get_content_for_region($region, $this); |
$lastblock = null; |
$zones = array();
|
foreach ($blockcontents as $bc) {
|
$zones[] = $bc->title;
|
}
|
$output = ''; |
foreach ($blockcontents as $bc) {
|
if ($bc instanceof block_contents) { |
$output .= $this->block($bc, $region); |
$lastblock = $bc->title;
|
} else if ($bc instanceof block_move_target) { |
$output .= $this->block_move_target($bc, $zones, $lastblock, $region); |
} else { |
throw new coding_exception('Unexpected type of thing (' . get_class($bc) . ') found in list of block contents.'); |
}
|
}
|
return $output; |
}
|
will result in '$zones' having exactly the same data! But without the need to call 'get_blocks_for_region' and return a large data structure.