diff --git a/lib/classes/navigation/views/primary.php b/lib/classes/navigation/views/primary.php new file mode 100644 index 00000000000..67f45c7ebe6 --- /dev/null +++ b/lib/classes/navigation/views/primary.php @@ -0,0 +1,67 @@ +. + +namespace core\navigation\views; + +/** + * Class primary. + * + * The primary navigation view is a combination of few components - navigation, output->navbar, + * + * @package core + * @category navigation + * @copyright 2021 onwards Peter Dias + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class primary extends view { + /** + * Initialise the primary navigation node + */ + public function initialise(): void { + if (during_initial_install() || $this->initialised) { + return; + } + $this->id = 'primary_navigation'; + $this->add(get_string('home'), new \moodle_url('/'), self::TYPE_SYSTEM, + null, 'home', new \pix_icon('i/home', '')); + + // Add the dashboard link. + if (isloggedin() && !isguestuser()) { // Makes no sense if you aren't logged in. + $this->rootnodes['home'] = $this->add(get_string('myhome'), new \moodle_url('/my/'), + self::TYPE_SETTING, null, 'myhome', new \pix_icon('i/dashboard', '')); + } + + // Add a dummy mycourse link to a mycourses page. + $this->add(get_string('mycourses'), new \moodle_url('/course/index.php'), self::TYPE_ROOTNODE, null, 'courses'); + + // Add the site admin node. We are using the settingsnav so as to avoid rechecking permissions again. + $settingsnav = $this->page->settingsnav; + $node = $settingsnav->find('siteadministration', self::TYPE_SITE_ADMIN); + if (!$node) { + // Try again. This node can exist with 2 different keys. + $node = $settingsnav->find('root', self::TYPE_SITE_ADMIN); + } + + if ($node) { + // We don't need everything from the node just the initial link. + $this->add($node->text, $node->action(), self::TYPE_SITE_ADMIN, null, 'siteadminnode', $node->icon); + } + + // Search and set the active node. + $this->search_for_active_node(); + $this->initialised = true; + } +} diff --git a/lib/pagelib.php b/lib/pagelib.php index 481eb2e5814..2f08c914f6d 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -26,6 +26,7 @@ */ defined('MOODLE_INTERNAL') || die(); +use core\navigation\views\primary; use core\navigation\views\secondary; /** @@ -82,6 +83,7 @@ use core\navigation\views\secondary; * @property-read navbar $navbar The navbar object used to display the navbar * @property-read secondary $secondarynav The secondary navigation object * used to display the secondarynav in boost + * @property-read primary $primarynav The primary navigation object used to display the primary nav in boost * @property-read global_navigation $navigation The navigation structure for this page. * @property-read xhtml_container_stack $opencontainers Tracks XHTML tags on this page that have been opened but not closed. * mainly for internal use by the rendering code. @@ -303,6 +305,12 @@ class moodle_page { */ protected $_secondarynav = null; + /** + * @var primary Contains the nav nodes that will appear + * in the primary navigation. + */ + protected $_primarynav = null; + /** * @var navbar Contains the navbar structure. */ @@ -804,6 +812,18 @@ class moodle_page { return $this->_secondarynav; } + /** + * Returns the primary navigation object + * @return primary + */ + protected function magic_get_primarynav() { + if ($this->_primarynav === null) { + $this->_primarynav = new primary($this); + $this->_primarynav->initialise(); + } + return $this->_primarynav; + } + /** * Returns request IP address. * diff --git a/version.php b/version.php index 6797a5a73f8..2d0aa19bea6 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2021052500.73; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2021052500.74; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0dev (Build: 20210330)'; // Human-friendly version name