MDL-78850 course: allow to show/hide the course index drawer
This new API makes it easy for the developer to hide or show the course index drawer.
This commit is contained in:
@@ -3750,6 +3750,11 @@ function core_course_core_calendar_get_valid_event_timestart_range(\calendar_eve
|
||||
function core_course_drawer(): string {
|
||||
global $PAGE;
|
||||
|
||||
// If the course index is explicitly set and if it should be hidden.
|
||||
if ($PAGE->get_show_course_index() === false) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Only add course index on non-site course pages.
|
||||
if (!$PAGE->course || $PAGE->course->id == SITEID) {
|
||||
return '';
|
||||
|
||||
@@ -432,6 +432,11 @@ class moodle_page {
|
||||
*/
|
||||
protected $_forcelockallblocks = false;
|
||||
|
||||
/**
|
||||
* @var bool Indicates whether the course index drawer should be shown.
|
||||
*/
|
||||
protected bool $_showcourseindex = true;
|
||||
|
||||
/**
|
||||
* Force the settings menu to be displayed on this page. This will only force the
|
||||
* settings menu on an activity / resource page that is being displayed on a theme that
|
||||
@@ -2477,4 +2482,24 @@ class moodle_page {
|
||||
public function get_navigation_overflow_state(): bool {
|
||||
return $this->_navigationoverflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the status for displaying the course index.
|
||||
*
|
||||
* @param bool $state
|
||||
* - `true` (default) if the course index should be shown.
|
||||
* - `false` if the course index should be hidden.
|
||||
*/
|
||||
public function set_show_course_index(bool $state): void {
|
||||
$this->_showcourseindex = $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current status for displaying the course index.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get_show_course_index(): bool {
|
||||
return $this->_showcourseindex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -875,6 +875,19 @@ class moodle_page_test extends \advanced_testcase {
|
||||
$this->testpage->force_lock_all_blocks();
|
||||
$this->assertFalse($this->testpage->user_can_edit_blocks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the method to set and retrieve the show_course_index property.
|
||||
*
|
||||
* @covers ::set_show_course_index
|
||||
* @covers ::get_show_course_index
|
||||
* @return void
|
||||
*/
|
||||
public function test_show_course_index(): void {
|
||||
$page = new \moodle_page();
|
||||
$page->set_show_course_index(false);
|
||||
$this->assertFalse($page->get_show_course_index());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user