diff --git a/blocks/navigation/block_navigation.php b/blocks/navigation/block_navigation.php index 89afeeaecd5..73522fee8ff 100644 --- a/blocks/navigation/block_navigation.php +++ b/blocks/navigation/block_navigation.php @@ -180,9 +180,12 @@ class block_navigation extends block_base { $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; diff --git a/blocks/navigation/edit_form.php b/blocks/navigation/edit_form.php index 91733e35b10..0d36b6b09fa 100644 --- a/blocks/navigation/edit_form.php +++ b/blocks/navigation/edit_form.php @@ -39,7 +39,7 @@ class block_navigation_edit_form extends block_edit_form { 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); diff --git a/blocks/navigation/lang/en/block_navigation.php b/blocks/navigation/lang/en/block_navigation.php index b6496c1695c..1fb2aa3f191 100644 --- a/blocks/navigation/lang/en/block_navigation.php +++ b/blocks/navigation/lang/en/block_navigation.php @@ -30,6 +30,7 @@ $string['coursestructures'] = 'Categories, courses, and course structures'; $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'; diff --git a/blocks/navigation/renderer.php b/blocks/navigation/renderer.php index 13d6aa3ad8c..6ef43a40df6 100644 --- a/blocks/navigation/renderer.php +++ b/blocks/navigation/renderer.php @@ -1,17 +1,17 @@ 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) { @@ -41,32 +41,23 @@ class block_navigation_renderer extends plugin_renderer_base { 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 @@ -100,7 +91,7 @@ class block_navigation_renderer extends plugin_renderer_base { 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; } diff --git a/lib/ajax/getnavbranch.php b/lib/ajax/getnavbranch.php index 3e4390ca75a..623f790a10d 100644 --- a/lib/ajax/getnavbranch.php +++ b/lib/ajax/getnavbranch.php @@ -47,6 +47,8 @@ try { // 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')); @@ -66,6 +68,9 @@ try { if (!empty($block->config->trimlength)) { $trimlength = (int)$block->config->trimlength; } + if (!empty($block->config->linkcategories) && $block->config->linkcategories == 'yes') { + $linkcategories = true; + } } } @@ -85,6 +90,13 @@ try { // 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(); diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 6b0f16375b2..4e759f2552d 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -1284,7 +1284,7 @@ class global_navigation extends navigation_node { 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;