MDL-66477 mod_forum: move region main settings menu to header
Add a generic way to render actions in the page content header and then moved the region main settings menu there for the forum.
This commit is contained in:
committed by
Jun Pataleta
parent
8aca1807ae
commit
c77d1ae40f
@@ -4261,6 +4261,14 @@ EOD;
|
||||
public function full_header() {
|
||||
global $PAGE;
|
||||
|
||||
if ($PAGE->include_region_main_settings_in_header_actions()) {
|
||||
$PAGE->add_header_action(html_writer::div(
|
||||
$this->region_main_settings_menu(),
|
||||
'd-print-none',
|
||||
['id' => 'region-main-settings-menu']
|
||||
));
|
||||
}
|
||||
|
||||
$header = new stdClass();
|
||||
$header->settingsmenu = $this->context_header_settings_menu();
|
||||
$header->contextheader = $this->context_header();
|
||||
@@ -4268,6 +4276,7 @@ EOD;
|
||||
$header->navbar = $this->navbar();
|
||||
$header->pageheadingbutton = $this->page_heading_button();
|
||||
$header->courseheader = $this->course_header();
|
||||
$header->headeractions = $PAGE->get_header_actions();
|
||||
return $this->render_from_template('core/full_header', $header);
|
||||
}
|
||||
|
||||
|
||||
@@ -353,6 +353,16 @@ class moodle_page {
|
||||
*/
|
||||
protected $_forcesettingsmenu = false;
|
||||
|
||||
/**
|
||||
* @var array Array of header actions HTML to add to the page header actions menu.
|
||||
*/
|
||||
protected $_headeractions = [];
|
||||
|
||||
/**
|
||||
* @var bool Should the region main settings menu be rendered in the header.
|
||||
*/
|
||||
protected $_regionmainsettingsinheader = false;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -2032,4 +2042,42 @@ class moodle_page {
|
||||
// Finally add the report to the navigation tree.
|
||||
$reportnode->add($nodeinfo['name'], $nodeinfo['url'], navigation_node::TYPE_COURSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some HTML to the list of actions to render in the header actions menu.
|
||||
*
|
||||
* @param string $html The HTML to add.
|
||||
*/
|
||||
public function add_header_action(string $html) : void {
|
||||
$this->_headeractions[] = $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of HTML for actions to render in the header actions menu.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function get_header_actions() : array {
|
||||
return $this->_headeractions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the flag to indicate if the region main settings should be rendered as an action
|
||||
* in the header actions menu rather than at the top of the content.
|
||||
*
|
||||
* @param bool $value If the settings should be in the header.
|
||||
*/
|
||||
public function set_include_region_main_settings_in_header_actions(bool $value) : void {
|
||||
$this->_regionmainsettingsinheader = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the region main settings should be rendered as an action in the header actions
|
||||
* menu rather than at the top of the content.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function include_region_main_settings_in_header_actions() : bool {
|
||||
return $this->_regionmainsettingsinheader;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<div class="col-12 pt-3 pb-3">
|
||||
<div class="card {{^contextheader}}border-0 bg-transparent{{/contextheader}}">
|
||||
<div class="card-body {{^contextheader}}p-2{{/contextheader}}">
|
||||
<div class="d-flex">
|
||||
<div class="d-flex align-items-center">
|
||||
{{#contextheader}}
|
||||
<div class="mr-auto">
|
||||
{{{contextheader}}}
|
||||
@@ -44,6 +44,11 @@
|
||||
{{{settingsmenu}}}
|
||||
</div>
|
||||
{{/settingsmenu}}
|
||||
<div class="header-actions-container flex-shrink-0" data-region="header-actions-container">
|
||||
{{#headeractions}}
|
||||
<div class="header-action ml-2">{{{.}}}</div>
|
||||
{{/headeractions}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap">
|
||||
{{#hasnavbar}}
|
||||
|
||||
@@ -89,6 +89,7 @@ $PAGE->set_title($forum->get_name());
|
||||
$PAGE->add_body_class('forumtype-' . $forum->get_type() . ' reset-style');
|
||||
$PAGE->set_heading($course->fullname);
|
||||
$PAGE->set_button(forum_search_form($course, $search));
|
||||
$PAGE->set_include_region_main_settings_in_header_actions(true);
|
||||
|
||||
if ($istypesingle && $displaymode == FORUM_MODE_MODERN) {
|
||||
$PAGE->add_body_class('modern-display-mode reset-style');
|
||||
|
||||
@@ -39,7 +39,9 @@ if ($navdraweropen) {
|
||||
$bodyattributes = $OUTPUT->body_attributes($extraclasses);
|
||||
$blockshtml = $OUTPUT->blocks('side-pre');
|
||||
$hasblocks = strpos($blockshtml, 'data-block=') !== false;
|
||||
$regionmainsettingsmenu = $OUTPUT->region_main_settings_menu();
|
||||
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions();
|
||||
// If the settings menu will be included in the header then don't add it here.
|
||||
$regionmainsettingsmenu = $buildregionmainsettings ? $OUTPUT->region_main_settings_menu() : false;
|
||||
$templatecontext = [
|
||||
'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]),
|
||||
'output' => $OUTPUT,
|
||||
|
||||
@@ -69,6 +69,20 @@ $blocks-plus-gutter: $blocks-column-width + ( $grid-gutter-width / 2 );
|
||||
}
|
||||
}
|
||||
|
||||
.header-action {
|
||||
#region-main-settings-menu {
|
||||
position: unset;
|
||||
float: none;
|
||||
width: auto;
|
||||
|
||||
& > div {
|
||||
position: unset;
|
||||
right: auto;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[data-region="blocks-column"] {
|
||||
@include media-breakpoint-down(lg) {
|
||||
width: 100%;
|
||||
|
||||
@@ -12164,6 +12164,15 @@ div.editor_atto_toolbar button .icon {
|
||||
If modifying make sure block-region is horizontally stacked when in full screen */
|
||||
display: block; } }
|
||||
|
||||
.header-action #region-main-settings-menu {
|
||||
position: unset;
|
||||
float: none;
|
||||
width: auto; }
|
||||
.header-action #region-main-settings-menu > div {
|
||||
position: unset;
|
||||
right: auto;
|
||||
margin: 0; }
|
||||
|
||||
@media (max-width: 1199.98px) {
|
||||
[data-region="blocks-column"] {
|
||||
width: 100%; } }
|
||||
|
||||
@@ -12420,6 +12420,15 @@ div.editor_atto_toolbar button .icon {
|
||||
If modifying make sure block-region is horizontally stacked when in full screen */
|
||||
display: block; } }
|
||||
|
||||
.header-action #region-main-settings-menu {
|
||||
position: unset;
|
||||
float: none;
|
||||
width: auto; }
|
||||
.header-action #region-main-settings-menu > div {
|
||||
position: unset;
|
||||
right: auto;
|
||||
margin: 0; }
|
||||
|
||||
@media (max-width: 1199.98px) {
|
||||
[data-region="blocks-column"] {
|
||||
width: 100%; } }
|
||||
|
||||
@@ -31,10 +31,15 @@
|
||||
<div class="col-12 pt-3 pb-3">
|
||||
<div class="card {{^contextheader}}border-0 bg-transparent{{/contextheader}}">
|
||||
<div class="card-body {{^contextheader}}p-2{{/contextheader}}">
|
||||
<div class="d-flex">
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="mr-auto">
|
||||
{{{contextheader}}}
|
||||
</div>
|
||||
<div class="header-actions-container flex-shrink-0" data-region="header-actions-container">
|
||||
{{#headeractions}}
|
||||
<div class="header-action ml-2">{{{.}}}</div>
|
||||
{{/headeractions}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap">
|
||||
{{#hasnavbar}}
|
||||
|
||||
Reference in New Issue
Block a user