Created
June 4, 2019 16:39
-
-
Save sammarshallou/2c5a9286b02bcfa92c916a4ea2c2b90d to your computer and use it in GitHub Desktop.
How to have a Moodle block add itself to the dashboard page for everyone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This file is part of Moodle - http://moodle.org/ | |
// | |
// Moodle is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// | |
// Moodle is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
// GNU General Public License for more details. | |
// | |
// You should have received a copy of the GNU General Public License | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
/** | |
* Add site links block to the dashboard page for all users. | |
* | |
* @package block_ousitelinks | |
* @copyright 2019 The Open University | |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
*/ | |
defined('MOODLE_INTERNAL') || die(); | |
/** | |
* Adds block to dashboard. | |
* | |
* @param bool $evenwhentesting If true, add block even when testing | |
* @throws moodle_exception | |
*/ | |
function xmldb_block_ousitelinks_install(bool $evenwhentesting = false) { | |
// Do not add block on test setup because it may break core tests. (This function can be | |
// called with parameter true to force it to add for specific tests.) | |
if (!$evenwhentesting && (PHPUNIT_TEST || defined('BEHAT_SITE_RUNNING'))) { | |
return; | |
} | |
// Add block using API. | |
$mypage = new moodle_page(); | |
$mypage->set_context(\context_system::instance()); | |
$mypage->set_pagelayout('mydashboard'); | |
$mypage->set_pagetype('my-index'); | |
$mypage->blocks->add_region('content'); | |
$mypage->blocks->get_regions(); | |
$mypage->blocks->add_block('ousitelinks', 'content', 0, true, 'my-index'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment