mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-73370 contentbank: Move settings cog to tertiary navigation
* Add headings to subpages * Update context header based on current context * Tweak layout.
This commit is contained in:
parent
6652ec135b
commit
57f1bd3a01
@ -44,6 +44,8 @@ class helper {
|
||||
global $PAGE, $DB;
|
||||
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_heading(self::get_page_heading($context));
|
||||
$PAGE->set_secondary_active_tab('contentbank');
|
||||
$cburl = new \moodle_url('/contentbank/index.php', ['contextid' => $context->id]);
|
||||
|
||||
switch ($context->contextlevel) {
|
||||
@ -68,4 +70,27 @@ class helper {
|
||||
$PAGE->set_pagelayout('standard');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the page heading based on the current context
|
||||
*
|
||||
* @param \context $context The current context of the page
|
||||
* @return string
|
||||
*/
|
||||
public static function get_page_heading(\context $context): string {
|
||||
global $SITE;
|
||||
|
||||
$title = get_string('contentbank');
|
||||
if ($context->id == \context_system::instance()->id) {
|
||||
$title = $SITE->fullname;
|
||||
} else if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$course = get_course($context->instanceid);
|
||||
$title = $course->fullname;
|
||||
} else if ($context->contextlevel == CONTEXT_COURSECAT) {
|
||||
$category = \core_course_category::get($context->instanceid);
|
||||
$title = $category->get_formatted_name();
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,100 @@ class viewcontent implements renderable, templatable {
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content of the "More" dropdown in the tertiary navigation
|
||||
*
|
||||
* @return array|null The options to be displayed in a dropdown in the tertiary navigation
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
protected function get_edit_actions_dropdown(): ?array {
|
||||
global $PAGE;
|
||||
$options = [];
|
||||
if ($this->contenttype->can_manage($this->content)) {
|
||||
// Add the visibility item to the menu.
|
||||
switch($this->content->get_visibility()) {
|
||||
case content::VISIBILITY_UNLISTED:
|
||||
$visibilitylabel = get_string('visibilitysetpublic', 'core_contentbank');
|
||||
$newvisibility = content::VISIBILITY_PUBLIC;
|
||||
break;
|
||||
case content::VISIBILITY_PUBLIC:
|
||||
$visibilitylabel = get_string('visibilitysetunlisted', 'core_contentbank');
|
||||
$newvisibility = content::VISIBILITY_UNLISTED;
|
||||
break;
|
||||
default:
|
||||
$url = new \moodle_url('/contentbank/index.php', ['contextid' => $this->content->get_contextid()]);
|
||||
throw new moodle_exception('contentvisibilitynotfound', 'error', $url, $this->content->get_visibility());
|
||||
}
|
||||
|
||||
if ($visibilitylabel) {
|
||||
$options[$visibilitylabel] = [
|
||||
'data-action' => 'setcontentvisibility',
|
||||
'data-visibility' => $newvisibility,
|
||||
'data-contentid' => $this->content->get_id(),
|
||||
];
|
||||
}
|
||||
|
||||
// Add the rename content item to the menu.
|
||||
$options[get_string('rename')] = [
|
||||
'data-action' => 'renamecontent',
|
||||
'data-contentname' => $this->content->get_name(),
|
||||
'data-contentid' => $this->content->get_id(),
|
||||
];
|
||||
|
||||
if ($this->contenttype->can_upload()) {
|
||||
$options[get_string('replacecontent', 'contentbank')] = ['data-action' => 'upload'];
|
||||
|
||||
$PAGE->requires->js_call_amd(
|
||||
'core_contentbank/upload',
|
||||
'initModal',
|
||||
[
|
||||
'[data-action=upload]',
|
||||
\core_contentbank\form\upload_files::class,
|
||||
$this->content->get_contextid(),
|
||||
$this->content->get_id()
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->contenttype->can_download($this->content)) {
|
||||
$url = new moodle_url($this->contenttype->get_download_url($this->content));
|
||||
$options[get_string('download')] = [
|
||||
'url' => $url->out()
|
||||
];
|
||||
}
|
||||
|
||||
// Add the delete content item to the menu.
|
||||
if ($this->contenttype->can_delete($this->content)) {
|
||||
$options[get_string('delete')] = [
|
||||
'data-action' => 'deletecontent',
|
||||
'data-contentname' => $this->content->get_name(),
|
||||
'data-uses' => count($this->content->get_uses()),
|
||||
'data-contentid' => $this->content->get_id(),
|
||||
'data-contextid' => $this->content->get_contextid(),
|
||||
];
|
||||
}
|
||||
|
||||
$dropdown = [];
|
||||
if ($options) {
|
||||
foreach ($options as $key => $attribs) {
|
||||
$url = $attribs['url'] ?? '#';
|
||||
$dropdown['options'][] = [
|
||||
'label' => $key,
|
||||
'url' => $url,
|
||||
'attributes' => array_map(function ($key, $value) {
|
||||
return [
|
||||
'name' => $key,
|
||||
'value' => $value
|
||||
];
|
||||
}, array_keys($attribs), $attribs)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $dropdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export this data so it can be used as the context for a mustache template.
|
||||
*
|
||||
@ -88,6 +182,11 @@ class viewcontent implements renderable, templatable {
|
||||
|
||||
$closeurl = new moodle_url('/contentbank/index.php', ['contextid' => $this->content->get_contextid()]);
|
||||
$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) {
|
||||
$data->heading = get_string('visibilitytitleunlisted', 'contentbank', $data->heading);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class editor extends edit_content {
|
||||
* Defines the form fields.
|
||||
*/
|
||||
protected function definition() {
|
||||
global $DB;
|
||||
global $DB, $OUTPUT;
|
||||
|
||||
$mform = $this->_form;
|
||||
$errors = [];
|
||||
@ -70,6 +70,7 @@ class editor extends edit_content {
|
||||
$this->h5peditor = new h5peditor();
|
||||
|
||||
$this->set_display_vertical();
|
||||
$mform->addElement('html', $OUTPUT->heading($this->_customdata['heading'], 2));
|
||||
|
||||
if ($id) {
|
||||
// The H5P editor needs the H5P content id (h5p table).
|
||||
@ -114,7 +115,6 @@ class editor extends edit_content {
|
||||
}
|
||||
$mform->addElement('cancel', 'cancel', get_string('back'));
|
||||
} else {
|
||||
$this->add_action_buttons();
|
||||
$this->h5peditor->add_editor_to_form($mform);
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
@ -76,7 +76,8 @@ if (!$contenttype->can_edit($content)) {
|
||||
$values = [
|
||||
'contextid' => $contextid,
|
||||
'plugin' => $pluginname,
|
||||
'id' => $id
|
||||
'id' => $id,
|
||||
'heading' => $heading
|
||||
];
|
||||
|
||||
$title = get_string('contentbank');
|
||||
@ -91,8 +92,6 @@ $PAGE->navbar->add(get_string('edit'));
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
|
||||
$PAGE->set_heading($heading);
|
||||
|
||||
// Instantiate the content type form.
|
||||
$editorclass = "$contenttypename\\form\\editor";
|
||||
if (!class_exists($editorclass)) {
|
||||
|
@ -52,7 +52,6 @@ if ($contextid == \context_system::instance()->id) {
|
||||
$PAGE->set_context($context);
|
||||
}
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
$PAGE->add_body_class('limitedwidth');
|
||||
$PAGE->set_pagetype('contentbank');
|
||||
$PAGE->set_secondary_active_tab('contentbank');
|
||||
@ -110,6 +109,7 @@ if (has_capability('moodle/contentbank:upload', $context)) {
|
||||
}
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($title, 2);
|
||||
echo $OUTPUT->box_start('generalbox');
|
||||
|
||||
// If needed, display notifications.
|
||||
|
57
contentbank/templates/contentbankmenu.mustache
Normal file
57
contentbank/templates/contentbankmenu.mustache
Normal file
@ -0,0 +1,57 @@
|
||||
{{!
|
||||
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 comments.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_contentbank/contentbankmenu
|
||||
|
||||
Contentbank view toolbar.
|
||||
|
||||
Classes required for JS:
|
||||
* none
|
||||
|
||||
Data attributes required for JS:
|
||||
* none
|
||||
|
||||
Context variables required for this template:
|
||||
* options - JSON object - the options available in the dropdown
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"options": [
|
||||
{
|
||||
"url": "www.google.com",
|
||||
"label": "Google",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "data-attrib",
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}}
|
||||
<div class="dropdown d-flex">
|
||||
<button aria-label="{{#str}}actionsmenu{{/str}}" class="btn btn-secondary dropdown-toggle" id="dropdown-actions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
{{#str}}more, core_contentbank{{/str}}
|
||||
</button>
|
||||
|
||||
<div class="dropdown-menu" aria-labelledby="dropdown-actions">
|
||||
{{#options}}
|
||||
<a class="dropdown-item" {{#attributes}}{{name}}="{{value}}"{{/attributes}} href="{{url}}">{{label}}</a>
|
||||
{{/options}}
|
||||
</div>
|
||||
</div>
|
@ -44,5 +44,4 @@
|
||||
<div class="mt-1 mb-1" data-region="viewcontent-content">
|
||||
{{{ contenthtml }}}
|
||||
</div>
|
||||
{{>core_contentbank/viewcontent/toolbarview}}
|
||||
</div>
|
||||
|
@ -34,17 +34,51 @@ along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
Example context (json):
|
||||
{
|
||||
"usercanedit" : true,
|
||||
"heading" : "This is a heading",
|
||||
"editcontenturl" : "http://something/contentbank/edit.php?contextid=1&plugin=h5p&id=1",
|
||||
"closeurl" : "http://moodle.test/h5pcb/moodle/contentbank/index.php"
|
||||
"closeurl" : "http://moodle.test/h5pcb/moodle/contentbank/index.php",
|
||||
"actionmenu": {
|
||||
"options": [
|
||||
{
|
||||
"url": "www.google.com",
|
||||
"label": "Google",
|
||||
"attributes": [
|
||||
{
|
||||
"name": "data-attrib",
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}}
|
||||
{{#heading}}<h2>{{heading}}</h2>{{/heading}}
|
||||
{{#usercanedit}}
|
||||
<div class="cb-toolbar-container my-2">
|
||||
<a href="{{editcontenturl}}" class="btn btn-primary" data-action="edit-content">
|
||||
{{#str}}edit{{/str}}
|
||||
</a>
|
||||
<a href="{{closeurl}}" class="btn btn-secondary" data-action="close-content">
|
||||
{{#str}}close, core_contentbank{{/str}}
|
||||
</a>
|
||||
<div class="cb-toolbar-container container-fluid my-2">
|
||||
<div class="row">
|
||||
<div class="d-flex">
|
||||
<a href="{{editcontenturl}}" class="btn btn-primary" data-action="edit-content">
|
||||
{{#str}}edit{{/str}}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{{#actionmenu}}
|
||||
<div class="ml-3">
|
||||
{{> core_contentbank/contentbankmenu }}
|
||||
</div>
|
||||
{{/actionmenu}}
|
||||
|
||||
<div class="ml-auto">
|
||||
<a href="{{closeurl}}" class="btn btn-secondary" data-action="close-content">
|
||||
{{#str}}exit, core_contentbank{{/str}}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/usercanedit}}
|
||||
{{^usercanedit}}
|
||||
{{#actionmenu}}
|
||||
{{> core_contentbank/contentbankmenu }}
|
||||
{{/actionmenu}}
|
||||
{{/usercanedit}}
|
||||
|
@ -55,122 +55,20 @@ if ($PAGE->course) {
|
||||
$cb = new \core_contentbank\contentbank();
|
||||
$content = $cb->get_content_from_id($record->id);
|
||||
$contenttype = $content->get_content_type_instance();
|
||||
$pageheading = $record->name;
|
||||
|
||||
if (!$content->is_view_allowed()) {
|
||||
$cburl = new \moodle_url('/contentbank/index.php', ['contextid' => $context->id, 'errormsg' => 'notavailable']);
|
||||
redirect($cburl);
|
||||
}
|
||||
|
||||
if ($content->get_visibility() == content::VISIBILITY_UNLISTED) {
|
||||
$pageheading = get_string('visibilitytitleunlisted', 'contentbank', $record->name);
|
||||
}
|
||||
|
||||
$PAGE->set_url(new \moodle_url('/contentbank/view.php', ['id' => $id]));
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->navbar->add($record->name);
|
||||
$PAGE->set_heading($pageheading);
|
||||
$title .= ": ".$record->name;
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_pagetype('contentbank');
|
||||
$PAGE->set_pagelayout('incourse');
|
||||
|
||||
// Create the cog menu with all the secondary actions, such as delete, rename...
|
||||
$actionmenu = new action_menu();
|
||||
if ($contenttype->can_manage($content)) {
|
||||
// Add the visibility item to the menu.
|
||||
switch($content->get_visibility()) {
|
||||
case content::VISIBILITY_UNLISTED:
|
||||
$visibilitylabel = get_string('visibilitysetpublic', 'core_contentbank');
|
||||
$newvisibility = content::VISIBILITY_PUBLIC;
|
||||
$visibilityicon = 't/hide';
|
||||
break;
|
||||
case content::VISIBILITY_PUBLIC:
|
||||
$visibilitylabel = get_string('visibilitysetunlisted', 'core_contentbank');
|
||||
$newvisibility = content::VISIBILITY_UNLISTED;
|
||||
$visibilityicon = 't/show';
|
||||
break;
|
||||
default:
|
||||
print_error('contentvisibilitynotfound', 'error', $returnurl, $content->get_visibility());
|
||||
break;
|
||||
}
|
||||
|
||||
$attributes = [
|
||||
'data-action' => 'setcontentvisibility',
|
||||
'data-visibility' => $newvisibility,
|
||||
'data-contentid' => $content->get_id(),
|
||||
];
|
||||
$actionmenu->add_secondary_action(new action_menu_link(
|
||||
new moodle_url('#'),
|
||||
new pix_icon($visibilityicon, $visibilitylabel),
|
||||
$visibilitylabel,
|
||||
false,
|
||||
$attributes
|
||||
));
|
||||
|
||||
// Add the rename content item to the menu.
|
||||
$attributes = [
|
||||
'data-action' => 'renamecontent',
|
||||
'data-contentname' => $content->get_name(),
|
||||
'data-contentid' => $content->get_id(),
|
||||
];
|
||||
$actionmenu->add_secondary_action(new action_menu_link(
|
||||
new moodle_url('#'),
|
||||
new pix_icon('e/styleparagraph', get_string('rename')),
|
||||
get_string('rename'),
|
||||
false,
|
||||
$attributes
|
||||
));
|
||||
|
||||
if ($contenttype->can_upload()) {
|
||||
$actionmenu->add_secondary_action(new action_menu_link(
|
||||
new moodle_url('/contentbank/view.php', ['contextid' => $context->id, 'id' => $content->get_id()]),
|
||||
new pix_icon('i/upload', get_string('upload')),
|
||||
get_string('replacecontent', 'contentbank'),
|
||||
false,
|
||||
['data-action' => 'upload']
|
||||
));
|
||||
$PAGE->requires->js_call_amd(
|
||||
'core_contentbank/upload',
|
||||
'initModal',
|
||||
['[data-action=upload]', \core_contentbank\form\upload_files::class, $context->id, $content->get_id()]
|
||||
);
|
||||
}
|
||||
}
|
||||
if ($contenttype->can_download($content)) {
|
||||
// Add the download content item to the menu.
|
||||
$actionmenu->add_secondary_action(new action_menu_link(
|
||||
new moodle_url($contenttype->get_download_url($content)),
|
||||
new pix_icon('t/download', get_string('download')),
|
||||
get_string('download'),
|
||||
false
|
||||
));
|
||||
}
|
||||
if ($contenttype->can_delete($content)) {
|
||||
// Add the delete content item to the menu.
|
||||
$attributes = [
|
||||
'data-action' => 'deletecontent',
|
||||
'data-contentname' => $content->get_name(),
|
||||
'data-uses' => count($content->get_uses()),
|
||||
'data-contentid' => $content->get_id(),
|
||||
'data-contextid' => $context->id,
|
||||
];
|
||||
$actionmenu->add_secondary_action(new action_menu_link(
|
||||
new moodle_url('#'),
|
||||
new pix_icon('t/delete', get_string('delete')),
|
||||
get_string('delete'),
|
||||
false,
|
||||
$attributes
|
||||
));
|
||||
}
|
||||
|
||||
// Add the cog menu to the header.
|
||||
$PAGE->add_header_action(html_writer::div(
|
||||
$OUTPUT->render($actionmenu),
|
||||
'd-print-none',
|
||||
['id' => 'region-main-settings-menu']
|
||||
));
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// If needed, display notifications.
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
$string['author'] = 'Author';
|
||||
$string['contentbank'] = 'Content bank';
|
||||
$string['close'] = 'Close';
|
||||
$string['choosecontext'] = 'Choose course or category...';
|
||||
$string['contentbankpreferences'] = 'Content bank preferences';
|
||||
$string['contentdeleted'] = 'The content has been deleted.';
|
||||
@ -47,6 +46,7 @@ $string['eventcontentuploaded'] = 'Content uploaded';
|
||||
$string['eventcontentviewed'] = 'Content viewed';
|
||||
$string['errordeletingcontentfromcategory'] = 'Error deleting content from category {$a}.';
|
||||
$string['errornofile'] = 'A compatible file is needed to create content.';
|
||||
$string['exit'] = 'Exit';
|
||||
$string['deletecontent'] = 'Delete content';
|
||||
$string['deletecontentconfirm'] = 'Are you sure you want to delete the content <em>\'{$a->name}\'</em> and all associated files? This action cannot be undone.';
|
||||
$string['deletecontentconfirmlinked'] = 'The content will only be deleted from the content bank. Any places which currently link to it will be automatically updated to use a copy of the content instead.';
|
||||
@ -56,6 +56,7 @@ $string['file'] = 'Upload content';
|
||||
$string['file_help'] = 'Files may be stored in the content bank for use in courses. Only files used by content types enabled on the site may be uploaded.';
|
||||
$string['itemsfound'] = '{$a} items found';
|
||||
$string['lastmodified'] = 'Last modified';
|
||||
$string['more'] = 'More';
|
||||
$string['name'] = 'Content';
|
||||
$string['nocontentavailable'] = 'No content available';
|
||||
$string['nocontenttypes'] = 'No content types available';
|
||||
@ -91,3 +92,6 @@ $string['visibilitypref_help'] = 'Content you create in the content bank will us
|
||||
$string['visibilitysetpublic'] = 'Make public';
|
||||
$string['visibilitysetunlisted'] = 'Make unlisted';
|
||||
$string['visibilitytitleunlisted'] = '{$a} (Unlisted)';
|
||||
|
||||
// Deprecated since 4.0.
|
||||
$string['close'] = 'Close';
|
||||
|
@ -78,3 +78,4 @@ loggedoff_help,core_message
|
||||
loggedoffdescription,core_message
|
||||
sendingvia,core_message
|
||||
sendingviawhen,core_message
|
||||
close,core_contentbank
|
Loading…
x
Reference in New Issue
Block a user