.
/**
* Renderers to align Moodle's HTML with that expected by Bootstrap
*
* @package theme_bootstrap
* @copyright 2012
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class theme_bootstrap_core_renderer extends core_renderer {
/*
* This renders a notification message.
* Uses bootstrap compatible html.
*/
public function notification($message, $classes = 'notifyproblem') {
$message = clean_text($message);
$type = '';
if ($classes == 'notifyproblem') {
$type = 'alert alert-error';
}
if ($classes == 'notifysuccess') {
$type = 'alert alert-success';
}
if ($classes == 'notifymessage') {
$type = 'alert alert-info';
}
if ($classes == 'redirectmessage') {
$type = 'alert alert-block alert-info';
}
return "
$message
";
}
/*
* This renders the navbar.
* Uses bootstrap compatible html.
*/
public function navbar() {
$items = $this->page->navbar->get_items();
foreach ($items as $item) {
$item->hideicon = true;
$breadcrumbs[] = $this->render($item);
}
$divider = '/';
$list_items = ''.join(" $divider", $breadcrumbs).'';
$title = ''.get_string('pagepath').'';
return $title . "";
}
/*
* Overriding the custom_menu function ensures the custom menu is
* always shown, even if no menu items are configured in the global
* theme settings page.
* We use the sitename as the first menu item.
*/
public function custom_menu($custommenuitems = '') {
global $CFG;
if (!empty($CFG->custommenuitems)) {
$custommenuitems .= $CFG->custommenuitems;
}
$custommenu = new custom_menu($custommenuitems, current_language());
return $this->render_custom_menu($custommenu);
}
/*
* This renders the bootstrap top menu.
*
* This renderer is needed to enable the Bootstrap style navigation.
*/
protected function render_custom_menu(custom_menu $menu) {
// If the menu has no children return an empty string.
if (!$menu->has_children()) {
return '';
}
$addlangmenu = true;
$langs = get_string_manager()->get_list_of_translations();
if ($this->page->course != SITEID and !empty($this->page->course->lang)) {
// Do not show lang menu if language forced.
$addlangmenu = false;
}
if (count($langs) < 2) {
$addlangmenu = false;
}
if ($addlangmenu) {
$language = $menu->add(get_string('language'), new moodle_url('#'), get_string('language'), 10);
foreach ($langs as $langtype => $langname) {
$language->add($langname,
new moodle_url($this->page->url, array('lang' => $langtype)), $langname);
}
}
$content = '';
foreach ($menu->get_children() as $item) {
$content .= $this->render_custom_menu_item($item, 1);
}
return $content.'
';
}
/*
* This code renders the custom menu items for the
* bootstrap dropdown menu.
*/
protected function render_custom_menu_item(custom_menu_item $menunode, $level = 0 ) {
static $submenucount = 0;
if ($menunode->has_children()) {
if ($level == 1) {
$dropdowntype = 'dropdown';
} else {
$dropdowntype = 'dropdown-submenu';
}
$content = html_writer::start_tag('li', array('class'=>$dropdowntype));
// If the child has menus render it as a sub menu.
$submenucount++;
if ($menunode->get_url() !== null) {
$url = $menunode->get_url();
} else {
$url = '#cm_submenu_'.$submenucount;
}
$content .= html_writer::start_tag('a', array('href'=>$url, 'class'=>'dropdown-toggle', 'data-toggle'=>'dropdown'));
$content .= $menunode->get_title();
if ($level == 1) {
$content .= '';
}
$content .= '';
$content .= '';
} else {
$content = '';
// The node doesn't have children so produce a final menuitem.
if ($menunode->get_url() !== null) {
$url = $menunode->get_url();
} else {
$url = '#';
}
$content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
}
return $content;
}
}