From 2b0a0cecdfcb227381edb13dae8225add852406c Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 27 Mar 2023 17:54:34 +0100 Subject: [PATCH] MDL-77762 contentbank: always provide exit button when appropriate. If the current user can access the content bank in the context of the current item, then provide link back to it. --- contentbank/classes/output/viewcontent.php | 17 +++++++------- .../viewcontent/toolbarview.mustache | 23 ++++++++----------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/contentbank/classes/output/viewcontent.php b/contentbank/classes/output/viewcontent.php index b514c4da142..7813aafaf2c 100644 --- a/contentbank/classes/output/viewcontent.php +++ b/contentbank/classes/output/viewcontent.php @@ -14,16 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Class containing data for a content view. - * - * @package core_contentbank - * @copyright 2020 Victor Deniz - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ namespace core_contentbank\output; +use context; use core_contentbank\content; use core_contentbank\contenttype; use moodle_url; @@ -180,8 +174,13 @@ class viewcontent implements renderable, templatable { $data->editcontenturl = $editcontenturl->out(false); } - $closeurl = new moodle_url('/contentbank/index.php', ['contextid' => $this->content->get_contextid()]); - $data->closeurl = $closeurl->out(false); + // Close/exit link for those users who can access that context. + $context = context::instance_by_id($this->content->get_contextid()); + if (has_capability('moodle/contentbank:access', $context)) { + $closeurl = new moodle_url('/contentbank/index.php', ['contextid' => $context->id]); + $data->closeurl = $closeurl->out(false); + } + $data->actionmenu = $this->get_edit_actions_dropdown(); $data->heading = $this->content->get_name(); if ($this->content->get_visibility() == content::VISIBILITY_UNLISTED) { diff --git a/contentbank/templates/viewcontent/toolbarview.mustache b/contentbank/templates/viewcontent/toolbarview.mustache index 7dde8d58a82..02acfb0eaac 100644 --- a/contentbank/templates/viewcontent/toolbarview.mustache +++ b/contentbank/templates/viewcontent/toolbarview.mustache @@ -54,31 +54,28 @@ along with Moodle. If not, see . } }} {{#heading}}

{{heading}}

{{/heading}} -{{#usercanedit}}
-
+ {{#usercanedit}} + + {{/usercanedit}} - {{#actionmenu}} -
- {{> core_contentbank/contentbankmenu }} -
- {{/actionmenu}} + {{#actionmenu}} +
+ {{> core_contentbank/contentbankmenu }} +
+ {{/actionmenu}} + {{#closeurl}} + {{/closeurl}}
-{{/usercanedit}} -{{^usercanedit}} - {{#actionmenu}} - {{> core_contentbank/contentbankmenu }} - {{/actionmenu}} -{{/usercanedit}}