From 6fef2ab3dbe2c4f8f949f3c8dffa018db22f3ae5 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 21 Feb 2017 14:47:03 +0000 Subject: [PATCH] MDL-58040 blocklib: never use global in block manager class This switches everything to ->page, including coverting static method to real one. --- lib/blocklib.php | 16 +++++++--------- lib/tests/blocklib_test.php | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/blocklib.php b/lib/blocklib.php index 65403616251..296c55d4bba 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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()); } /** diff --git a/lib/tests/blocklib_test.php b/lib/tests/blocklib_test.php index b5b5454584e..6eb0fed8177 100644 --- a/lib/tests/blocklib_test.php +++ b/lib/tests/blocklib_test.php @@ -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);