Permalink
Browse files

MDL-35655 Navigation - Generalized fetching method of navigation obje…

…ct and renderer in navigation block
  • Loading branch information...
1 parent 5d6285c commit c8ed28175e6b3e6d85a2cd5e0b01aff67373bd53 @itamart itamart committed Sep 27, 2012
Showing with 16 additions and 4 deletions.
  1. +16 −4 blocks/navigation/block_navigation.php
@@ -177,9 +177,10 @@ function get_content() {
$trimlength = (int)$this->config->trimlength;
}
- // Initialise (only actually happens if it hasn't already been done yet
- $this->page->navigation->initialise();
- $navigation = clone($this->page->navigation);
+ // Get the navigation object or don't display the block if none provided.
+ if (!$navigation = $this->get_navigation()) {
+ return null;
+ }
$expansionlimit = null;
if (!empty($this->config->expansionlimit)) {
$expansionlimit = $this->config->expansionlimit;
@@ -204,7 +205,7 @@ function get_content() {
$options['linkcategories'] = (!empty($this->config->linkcategories) && $this->config->linkcategories == 'yes');
// Grab the items to display
- $renderer = $this->page->get_renderer('block_navigation');
+ $renderer = $this->page->get_renderer($this->blockname);
$this->content = new stdClass();
$this->content->text = $renderer->navigation_tree($navigation, $expansionlimit, $options);
@@ -215,6 +216,17 @@ function get_content() {
}
/**
+ * Returns the navigation
+ *
+ * @return navigation_node The navigation object to display
+ */
+ protected function get_navigation() {
+ // Initialise (only actually happens if it hasn't already been done yet)
+ $this->page->navigation->initialise();
+ return clone($this->page->navigation);
+ }
+
+ /**
* Returns the attributes to set for this block
*
* This function returns an array of HTML attributes for this block including

0 comments on commit c8ed281

Please sign in to comment.