add_to_config_log('block_visibility', $block->visible, '1', $block->name); core_plugin_manager::reset_caches(); admin_get_root(true, false); // settings not required - only pages } if (!empty($protect) && confirm_sesskey()) { block_manager::protect_block((int) $protect); admin_get_root(true, false); // settings not required - only pages } if (!empty($unprotect) && confirm_sesskey()) { block_manager::unprotect_block((int) $unprotect); admin_get_root(true, false); // settings not required - only pages } $undeletableblocktypes = block_manager::get_undeletable_block_types(); echo $OUTPUT->header(); echo $OUTPUT->heading($strmanageblocks); /// Main display starts here /// Get and sort the existing blocks if (!($blocks = $DB->get_records('block', array(), 'name ASC'))) { print_error('noblocks', 'error'); // Should never happen } $incompatible = array(); /// Print the table of all blocks $table = new flexible_table('admin-blocks-compatible'); $table->define_columns(array('name', 'instances', 'version', 'hideshow', 'undeletable', 'settings', 'uninstall')); $table->define_headers(array($strname, $strcourses, $strversion, $strhide . '/' . $strshow, $strprotecthdr, $strsettings, $struninstall)); $table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/blocks.php'); $table->set_attribute('class', 'admintable blockstable generaltable');
public function test_create_all_block_instances() { global $CFG, $PAGE, $DB; $this->resetAfterTest(); $regionname = 'side-pre'; $context = context_system::instance(); $PAGE->reset_theme_and_output(); $CFG->theme = 'boost'; list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type'); $blockmanager->load_blocks(); $blockmanager->create_all_block_instances(); $blocks = $blockmanager->get_blocks_for_region($regionname); $this->assertEmpty($blocks); // There should be no blocks in the DB. $PAGE->reset_theme_and_output(); // Change to a theme with undeletable blocks. $CFG->theme = 'clean'; list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type'); $blockmanager->show_only_fake_blocks(true); $blockmanager->load_blocks(); $blockmanager->create_all_block_instances(); $blocks = $blockmanager->get_blocks_for_region($regionname); $this->assertEmpty($blocks); $PAGE->reset_theme_and_output(); list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type'); $blockmanager->show_only_fake_blocks(false); $blockmanager->load_blocks(); $blockmanager->create_all_block_instances(); $blocks = $blockmanager->get_blocks_for_region($regionname); $this->assertCount(2, $blocks); $undeletable = block_manager::get_undeletable_block_types(); foreach ($undeletable as $blockname) { $instance = $DB->get_record('block_instances', array('blockname' => $blockname)); $this->assertEquals(1, $instance->requiredbytheme); } // Switch back and those auto blocks should not be returned. $PAGE->reset_theme_and_output(); $CFG->theme = 'boost'; list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname), $context, 'page-type'); $blockmanager->load_blocks(); $blockmanager->create_all_block_instances(); $blocks = $blockmanager->get_blocks_for_region($regionname); $this->assertEmpty($blocks); // But they should exist in the DB. foreach ($undeletable as $blockname) { $count = $DB->count_records('block_instances', array('blockname' => $blockname)); $this->assertEquals(1, $count); } }
/** * Add the default system-context blocks. E.g. the admin tree. */ function blocks_add_default_system_blocks() { global $DB; $page = new moodle_page(); $page->set_context(context_system::instance()); $page->blocks->add_blocks(array(BLOCK_POS_LEFT => block_manager::get_undeletable_block_types()), '*', null, true); $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_bookmarks')), 'admin-*', null, null, 2); if ($defaultmypage = $DB->get_record('my_pages', array('userid' => null, 'name' => '__default', 'private' => 1))) { $subpagepattern = $defaultmypage->id; } else { $subpagepattern = null; } $newblocks = array('private_files', 'online_users', 'badges', 'calendar_month', 'calendar_upcoming'); $newcontent = array('lp', 'course_overview'); $page->blocks->add_blocks(array(BLOCK_POS_RIGHT => $newblocks, 'content' => $newcontent), 'my-index', $subpagepattern); }