MDL-58040 blocklib: never use global in block manager class

This switches everything to ->page, including coverting static method to real one.
This commit is contained in:
Tim Hunt
2017-02-21 15:19:11 +00:00
parent 9ec952f237
commit 898da28afd
2 changed files with 8 additions and 10 deletions
+7 -9
View File
@@ -215,7 +215,7 @@ class block_manager {
}
$unaddableblocks = self::get_undeletable_block_types();
$requiredbythemeblocks = self::get_required_by_theme_block_types();
$requiredbythemeblocks = $this->get_required_by_theme_block_types();
$pageformat = $this->page->pagetype;
foreach($allblocks as $block) {
if (!$bi = block_instance($block->name)) {
@@ -246,7 +246,7 @@ class block_manager {
return false;
}
$requiredbythemeblocks = self::get_required_by_theme_block_types();
$requiredbythemeblocks = $this->get_required_by_theme_block_types();
foreach ($this->blockinstances as $region) {
foreach ($region as $instance) {
if (empty($instance->instance->blockname)) {
@@ -380,11 +380,10 @@ class block_manager {
/**
* @return array names of block types that must exist on every page with this theme.
*/
public static function get_required_by_theme_block_types() {
global $CFG, $PAGE;
public function get_required_by_theme_block_types() {
$requiredbythemeblocks = false;
if (isset($PAGE->theme->requiredblocks)) {
$requiredbythemeblocks = $PAGE->theme->requiredblocks;
if (isset($this->page->theme->requiredblocks)) {
$requiredbythemeblocks = $this->page->theme->requiredblocks;
}
if ($requiredbythemeblocks === false) {
@@ -457,7 +456,7 @@ class block_manager {
* @return array names of block types that cannot be added or deleted. E.g. array('navigation','settings').
*/
public static function get_undeletable_block_types() {
global $CFG, $PAGE;
global $CFG;
$undeletableblocks = false;
if (isset($CFG->undeletableblocktypes)) {
$undeletableblocks = $CFG->undeletableblocktypes;
@@ -1072,7 +1071,6 @@ class block_manager {
* so they are only visible on themes that require them.
*/
public function create_all_block_instances() {
global $PAGE;
$missing = false;
// If there are any un-removable blocks that were not created - force them.
@@ -1359,7 +1357,7 @@ class block_manager {
return $this->page->user_can_edit_blocks() && $block->user_can_edit() &&
$block->user_can_addto($this->page) &&
!in_array($block->instance->blockname, self::get_undeletable_block_types()) &&
!in_array($block->instance->blockname, self::get_required_by_theme_block_types());
!in_array($block->instance->blockname, $this->get_required_by_theme_block_types());
}
/**
+1 -1
View File
@@ -598,7 +598,7 @@ class core_blocklib_testcase extends advanced_testcase {
// Assert that protecting a block does not make it auto-created.
$this->assertCount(2, $blocks);
$requiredbytheme = block_manager::get_required_by_theme_block_types();
$requiredbytheme = $blockmanager->get_required_by_theme_block_types();
foreach ($requiredbytheme as $blockname) {
$instance = $DB->get_record('block_instances', array('blockname' => $blockname));
$this->assertEquals(1, $instance->requiredbytheme);