$arguments = array($this->instance->id, array('expansions'=>$expandable, 'instance'=>$this->instance->id, 'candock'=>$this->instance_can_be_docked(), 'courselimit'=>$limit));
$this->page->requires->js_init_call('M.block_navigation.init_add_tree', $arguments, false, $module);
+ $options = array();
+ $options['linkcategories'] = (!empty($this->config->linkcategories) && $this->config->linkcategories == 'yes');
+
// Grab the items to display
$renderer = $this->page->get_renderer('block_navigation');
- $this->content->text = $renderer->navigation_tree($navigation, $expansionlimit);
+ $this->content->text = $renderer->navigation_tree($navigation, $expansionlimit, $options);
// Set content generated to true so that we know it has been done
$this->contentgenerated = true;
global $CFG;
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
- $mods = array('enabledock'=>'yes');
+ $mods = array('enabledock'=>'yes', 'linkcategories'=>'no');
$yesnooptions = array('yes'=>get_string('yes'), 'no'=>get_string('no'));
foreach ($mods as $modname=>$default) {
$mform->addElement('select', 'config_'.$modname, get_string($modname.'desc', $this->block->blockname), $yesnooptions);
$string['courseactivities'] = 'Categories, courses, and course Activities';
$string['enabledockdesc'] = 'Allow the user to dock this block';
$string['expansionlimit'] = 'Generate navigation for the following';
+$string['linkcategoriesdesc'] = 'Display categories as links';
$string['pluginname'] = 'Navigation';
$string['trimmode'] = 'Trim mode';
$string['trimmoderight'] = 'Trim characters from the right';
<?php
class block_navigation_renderer extends plugin_renderer_base {
-
- public function navigation_tree(global_navigation $navigation, $expansionlimit) {
+
+ public function navigation_tree(global_navigation $navigation, $expansionlimit, array $options = array()) {
$navigation->add_class('navigation_node');
- $content = $this->navigation_node(array($navigation), array('class'=>'block_tree list'), $expansionlimit);
+ $content = $this->navigation_node(array($navigation), array('class'=>'block_tree list'), $expansionlimit, $options);
if (isset($navigation->id) && !is_numeric($navigation->id) && !empty($content)) {
$content = $this->output->box($content, 'block_tree_box', $navigation->id);
}
return $content;
}
- protected function navigation_node($items, $attrs=array(), $expansionlimit=null, $depth=1) {
+ protected function navigation_node($items, $attrs=array(), $expansionlimit=null, array $options = array(), $depth=1) {
// exit if empty, we don't want an empty ul element
if (count($items)==0) {
continue;
}
- if ($item->action instanceof action_link) {
+ $attributes = array();
+ if ($title !== '') {
+ $attributes['title'] = $title;
+ }
+ if ($item->hidden) {
+ $attributes['class'] = 'dimmed_text';
+ }
+ if (is_string($item->action) || empty($item->action) || ($item->type === navigation_node::TYPE_CATEGORY && empty($options['linkcategories']))) {
+ $content = html_writer::tag('span', $content, $attributes);
+ } else if ($item->action instanceof action_link) {
//TODO: to be replaced with something else
$link = $item->action;
- if ($item->hidden) {
- $link->add_class('dimmed');
- }
+ $link->attributes = array_merge($link->attributes, $attributes);
$content = $this->output->render($link);
+ $linkrendered = true;
} else if ($item->action instanceof moodle_url) {
- $attributes = array();
- if ($title !== '') {
- $attributes['title'] = $title;
- }
- if ($item->hidden) {
- $attributes['class'] = 'dimmed_text';
- }
$content = html_writer::link($item->action, $content, $attributes);
-
- } else if (is_string($item->action) || empty($item->action)) {
- $attributes = array();
- if ($title !== '') {
- $attributes['title'] = $title;
- }
- if ($item->hidden) {
- $attributes['class'] = 'dimmed_text';
- }
- $content = html_writer::tag('span', $content, $attributes);
}
// this applies to the li item which contains all child lists too
if (!empty($item->id)) {
$divattr['id'] = $item->id;
}
- $content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item->children, array(), $expansionlimit, $depth+1);
+ $content = html_writer::tag('p', $content, $divattr) . $this->navigation_node($item->children, array(), $expansionlimit, $options, $depth+1);
if (!empty($item->preceedwithhr) && $item->preceedwithhr===true) {
$content = html_writer::empty_tag('hr') . $content;
}
// Create a global nav object
$navigation = new global_navigation_for_ajax($PAGE, $branchtype, $branchid);
+ $linkcategories = false;
+
if ($instanceid!==null) {
// Get the db record for the block instance
$blockrecord = $DB->get_record('block_instances', array('id'=>$instanceid,'blockname'=>'navigation'));
if (!empty($block->config->trimlength)) {
$trimlength = (int)$block->config->trimlength;
}
+ if (!empty($block->config->linkcategories) && $block->config->linkcategories == 'yes') {
+ $linkcategories = true;
+ }
}
}
// Find the actuall branch we are looking for
$branch = $navigation->find($branchid, $branchtype);
+ // Remove links to categories if required.
+ if (!$linkcategories) {
+ foreach ($branch->find_all_of_type(navigation_node::TYPE_CATEGORY) as $category) {
+ $category->action = null;
+ }
+ }
+
// Stop buffering errors at this point
$html = ob_get_contents();
ob_end_clean();
if (!$categorynode) {
$category = $cat['category'];
$url = new moodle_url('/course/category.php', array('id'=>$category->id));
- $categorynode = $parent->add($category->name, null, self::TYPE_CATEGORY, $category->name, $category->id);
+ $categorynode = $parent->add($category->name, $url, self::TYPE_CATEGORY, $category->name, $category->id);
if (empty($category->visible)) {
if (has_capability('moodle/category:viewhiddencategories', get_system_context())) {
$categorynode->hidden = true;