2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @package tool_dataprivacy
21 * @copyright 2018 David Monllao
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace tool_dataprivacy
;
29 defined('MOODLE_INTERNAL') ||
die();
34 * @package tool_dataprivacy
35 * @copyright 2018 David Monllao
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 * Sets up $PAGE for data privacy admin pages.
43 * @param moodle_url $url The page URL.
44 * @param string $title The page's title.
45 * @param string $attachtoparentnode The parent navigation node where this page can be accessed from.
46 * @param string $requiredcapability The required capability to view this page.
48 public static function setup(moodle_url
$url, $title, $attachtoparentnode = '',
49 $requiredcapability = 'tool/dataprivacy:managedataregistry') {
52 $context = context_system
::instance();
56 print_error('noguest');
59 // TODO Check that data privacy is enabled.
60 require_capability($requiredcapability, $context);
62 $PAGE->navigation
->override_active_url($url);
65 $PAGE->set_context($context);
66 $PAGE->set_pagelayout('admin');
67 $PAGE->set_title($title);
68 $PAGE->set_heading($title);
70 // If necessary, override the settings navigation to add this page into the breadcrumb navigation.
71 if ($attachtoparentnode) {
72 if ($siteadmin = $PAGE->settingsnav
->find('root', \navigation_node
::TYPE_SITE_ADMIN
)) {
73 $PAGE->navbar
->add($siteadmin->get_content(), $siteadmin->action());
75 if ($dataprivacy = $PAGE->settingsnav
->find('privacy', \navigation_node
::TYPE_SETTING
)) {
76 $PAGE->navbar
->add($dataprivacy->get_content(), $dataprivacy->action());
78 if ($dataregistry = $PAGE->settingsnav
->find($attachtoparentnode, \navigation_node
::TYPE_SETTING
)) {
79 $PAGE->navbar
->add($dataregistry->get_content(), $dataregistry->action());
82 $PAGE->navbar
->add($title, $url);