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/>.
17 namespace theme_noname\output;
29 ||||||| parent of 6c769ad9e6... MDL-XXXX theme_noname: action-menu conversion
30 use preferences_groups;
32 use preferences_groups;
34 >>>>>>> 6c769ad9e6... MDL-XXXX theme_noname: action-menu conversion
36 defined('MOODLE_INTERNAL') || die;
39 * Renderers to align Moodle's HTML with that expected by Bootstrap
41 * @package theme_noname
42 * @copyright 2012 Bas Brands, www.basbrands.nl
43 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
46 class core_renderer extends \core_renderer {
48 /** @var custom_menu_item language The language menu if created */
49 protected $language = null;
52 * The standard tags that should be included in the <head> tag
53 * including a meta description for the front page
55 * @return string HTML fragment.
57 public function standard_head_html() {
60 $output = parent::standard_head_html();
61 if ($PAGE->pagelayout == 'frontpage') {
62 $summary = s(strip_tags(format_text($SITE->summary, FORMAT_HTML)));
63 if (!empty($summary)) {
64 $output .= "<meta name=\"description\" content=\"$summary\" />\n";
72 * This renders the navbar.
73 * Uses bootstrap compatible html.
75 public function navbar() {
76 $items = $this->page->navbar->get_items();
81 $breadcrumbs = array();
82 foreach ($items as $item) {
83 $item->hideicon = true;
84 $breadcrumbs[] = $this->render($item);
86 $list_items = '<li>'.join(" </li><li>", $breadcrumbs).'</li>';
87 $title = '<span class="accesshide" id="navbar-label">'.get_string('pagepath').'</span>';
88 return $title . '<nav aria-labelledby="navbar-label"><ul class="breadcrumb">' .
89 $list_items . '</ul></nav>';
93 * Overriding the custom_menu function ensures the custom menu is
94 * always shown, even if no menu items are configured in the global
95 * theme settings page.
97 public function custom_menu($custommenuitems = '') {
100 if (empty($custommenuitems) && !empty($CFG->custommenuitems)) {
101 $custommenuitems = $CFG->custommenuitems;
103 $custommenu = new custom_menu($custommenuitems, current_language());
104 return $this->render_custom_menu($custommenu);
108 * This renders the bootstrap top menu.
110 * This renderer is needed to enable the Bootstrap style navigation.
112 protected function render_custom_menu(custom_menu $menu) {
115 $langs = get_string_manager()->get_list_of_translations();
116 $haslangmenu = $this->lang_menu() != '';
118 if (!$menu->has_children() && !$haslangmenu) {
123 $strlang = get_string('language');
124 $currentlang = current_language();
125 if (isset($langs[$currentlang])) {
126 $currentlang = $langs[$currentlang];
128 $currentlang = $strlang;
130 $this->language = $menu->add($currentlang, new moodle_url('#'), $strlang, 10000);
131 foreach ($langs as $langtype => $langname) {
132 $this->language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname);
137 foreach ($menu->get_children() as $item) {
138 $context = $item->export_for_template($this);
139 $content .= $this->render_from_template('core/custom_menu_item', $context);
146 * This code renders the navbar button to control the display of the custom menu
147 * on smaller screens.
149 * Do not display the button if the menu is empty.
151 * @return string HTML fragment
153 public function navbar_button() {
156 if (empty($CFG->custommenuitems) && $this->lang_menu() == '') {
160 $iconbar = html_writer::tag('span', '', array('class' => 'icon-bar'));
161 $button = html_writer::tag('a', $iconbar . "\n" . $iconbar. "\n" . $iconbar, array(
162 'class' => 'btn btn-navbar',
163 'data-toggle' => 'collapse',
164 'data-target' => '.nav-collapse'
172 * @param tabtree $tabtree
175 protected function render_tabtree(tabtree $tabtree) {
176 if (empty($tabtree->subtree)) {
179 $data = $tabtree->export_for_template($this);
180 return $this->render_from_template('core/tabtree', $data);
184 * Renders tabobject (part of tabtree)
186 * This function is called from {@link core_renderer::render_tabtree()}
187 * and also it calls itself when printing the $tabobject subtree recursively.
189 * @param tabobject $tabobject
190 * @return string HTML fragment
192 protected function render_tabobject(tabobject $tab) {
193 throw new coding_exception('Tab objects should not be directly rendered.');
197 * Prints a nice side block with an optional header.
199 * @param block_contents $bc HTML for the content
200 * @param string $region the region the block is appearing in.
201 * @return string the HTML to be output.
203 public function block(block_contents $bc, $region) {
204 $bc = clone($bc); // Avoid messing up the object passed in.
205 if (empty($bc->blockinstanceid) || !strip_tags($bc->title)) {
206 $bc->collapsible = block_contents::NOT_HIDEABLE;
208 if (!empty($bc->blockinstanceid)) {
209 $bc->attributes['data-instanceid'] = $bc->blockinstanceid;
211 $skiptitle = strip_tags($bc->title);
212 if ($bc->blockinstanceid && !empty($skiptitle)) {
213 $bc->attributes['aria-labelledby'] = 'instance-'.$bc->blockinstanceid.'-header';
214 } else if (!empty($bc->arialabel)) {
215 $bc->attributes['aria-label'] = $bc->arialabel;
218 $bc->attributes['data-dockable'] = 1;
220 if ($bc->collapsible == block_contents::HIDDEN) {
221 $bc->add_class('hidden');
223 if (!empty($bc->controls)) {
224 $bc->add_class('block_with_controls');
227 $id = !empty($bc->attributes['id']) ? $bc->attributes['id'] : uniqid('block-');
228 $context = new stdClass();
229 $context->skipid = $bc->skipid;
230 $context->blockinstanceid = $bc->blockinstanceid;
231 $context->dockable = $bc->dockable;
233 $context->hidden = $bc->collapsible == block_contents::HIDDEN;
234 $context->skiptitle = strip_tags($bc->title);
235 $context->showskiplink = !empty($context->skiptitle);
236 $context->arialabel = $bc->arialabel;
237 $context->ariarole = !empty($bc->attributes['role']) ? $bc->attributes['role'] : 'complementary';
238 $context->type = $bc->attributes['data-block'];
239 $context->title = $bc->title;
240 $context->content = $bc->content;
241 $context->annotation = $bc->annotation;
242 $context->footer = $bc->footer;
243 $context->hascontrols = !empty($bc->controls);
244 if ($context->hascontrols) {
245 $context->controls = $this->block_controls($bc->controls, $id);
248 return $this->render_from_template('core/block', $context);
252 * Returns the CSS classes to apply to the body tag.
254 * @since Moodle 2.5.1 2.6
255 * @param array $additionalclasses Any additional classes to apply.
258 public function body_css_classes(array $additionalclasses = array()) {
259 return $this->page->bodyclasses;
263 * Renders preferences groups.
265 * @param preferences_groups $renderable The renderable
266 * @return string The output.
268 public function render_preferences_groups(preferences_groups $renderable) {
269 return $this->render_from_template('core/preferences_groups', $renderable);
273 * Renders preferences groups.
275 * @param preferences_groups $renderable The renderable
276 * @return string The output.
278 public function render_preferences_groups(preferences_groups $renderable) {
279 return $this->render_from_template('core/preferences_groups', $renderable);
283 * Renders an action menu component.
285 * @param action_menu $menu
286 * @return string HTML
288 public function render_action_menu(action_menu $menu) {
289 return $this->render_from_template('core/action_menu', $menu);