public $children = array();
/** @var bool A switch for whether we want to include the root node in the navbar */
public $includesettingsbase = false;
- /** @var navigation_node[] $prependchildren */
+ /** @var breadcrumb_navigation_node[] $prependchildren */
protected $prependchildren = array();
/**
* The almighty constructor
*
* @param moodle_page $page
*/
+
+
public function __construct(moodle_page $page) {
global $CFG;
if (during_initial_install()) {
* Gets a navigation node
*
* @param string|int $key for referencing the navbar nodes
- * @param int $type navigation_node::TYPE_*
- * @return navigation_node|bool
+ * @param int $type breadcrumb_navigation_node::TYPE_*
+ * @return breadcrumb_navigation_node|bool
*/
public function get($key, $type = null) {
foreach ($this->children as &$child) {
return false;
}
/**
- * Returns an array of navigation_node's that make up the navbar.
+ * Returns an array of breadcrumb_navigation_nodes that make up the navbar.
*
* @return array
*/
// Parse a combined navigation tree
while ($settingsactivenode && $settingsactivenode->parent !== null) {
if (!$settingsactivenode->mainnavonly) {
- $items[] = $settingsactivenode;
+ $items[] = new breadcrumb_navigation_node($settingsactivenode);
}
$settingsactivenode = $settingsactivenode->parent;
}
}
while ($navigationactivenode && $navigationactivenode->parent !== null) {
if (!$navigationactivenode->mainnavonly) {
- $items[] = $navigationactivenode;
+ $items[] = new breadcrumb_navigation_node($navigationactivenode);
}
if (!empty($CFG->navshowcategories) &&
$navigationactivenode->type === self::TYPE_COURSE &&
$navigationactivenode->parent->key === 'currentcourse') {
- $items = array_merge($items, $this->get_course_categories());
+ foreach ($this->get_course_categories() as $item) {
+ $items[] = new breadcrumb_navigation_node($item);
+ }
}
$navigationactivenode = $navigationactivenode->parent;
}
// Parse the navigation tree to get the active node
while ($navigationactivenode && $navigationactivenode->parent !== null) {
if (!$navigationactivenode->mainnavonly) {
- $items[] = $navigationactivenode;
+ $items[] = new breadcrumb_navigation_node($navigationactivenode);
}
if (!empty($CFG->navshowcategories) &&
$navigationactivenode->type === self::TYPE_COURSE &&
$navigationactivenode->parent->key === 'currentcourse') {
- $items = array_merge($items, $this->get_course_categories());
+ foreach ($this->get_course_categories() as $item) {
+ $items[] = new breadcrumb_navigation_node($item);
+ }
}
$navigationactivenode = $navigationactivenode->parent;
}
// Parse the settings navigation to get the active node
while ($settingsactivenode && $settingsactivenode->parent !== null) {
if (!$settingsactivenode->mainnavonly) {
- $items[] = $settingsactivenode;
+ $items[] = new breadcrumb_navigation_node($settingsactivenode);
}
$settingsactivenode = $settingsactivenode->parent;
}
}
}
- $items[] = new navigation_node(array(
- 'text'=>$this->page->navigation->text,
- 'shorttext'=>$this->page->navigation->shorttext,
- 'key'=>$this->page->navigation->key,
- 'action'=>$this->page->navigation->action
+ $items[] = new breadcrumb_navigation_node(array(
+ 'text' => $this->page->navigation->text,
+ 'shorttext' => $this->page->navigation->shorttext,
+ 'key' => $this->page->navigation->key,
+ 'action' => $this->page->navigation->action
));
if (count($this->prependchildren) > 0) {
}
$url = new moodle_url('/course/index.php', array('categoryid' => $category->id));
$name = format_string($category->name, true, array('context' => context_coursecat::instance($category->id)));
- $categorynode = navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id);
+ $categorynode = breadcrumb_navigation_node::create($name, $url, self::TYPE_CATEGORY, null, $category->id);
if (!$category->visible) {
$categorynode->hidden = true;
}
$courses = $this->page->navigation->get('courses');
if (!$courses) {
// Courses node may not be present.
- $courses = navigation_node::create(
+ $courses = breadcrumb_navigation_node::create(
get_string('courses'),
new moodle_url('/course/index.php'),
self::TYPE_CONTAINER
}
/**
- * Add a new navigation_node to the navbar, overrides parent::add
+ * Add a new breadcrumb_navigation_node to the navbar, overrides parent::add
*
- * This function overrides {@link navigation_node::add()} so that we can change
+ * This function overrides {@link breadcrumb_navigation_node::add()} so that we can change
* the way nodes get added to allow us to simply call add and have the node added to the
* end of the navbar
*
// Set the parent to this node
$itemarray['parent'] = $this;
// Add the child using the navigation_node_collections add method
- $this->children[] = new navigation_node($itemarray);
+ $this->children[] = new breadcrumb_navigation_node($itemarray);
return $this;
}
// Set the parent to this node.
$itemarray['parent'] = $this;
// Add the child node to the prepend list.
- $this->prependchildren[] = new navigation_node($itemarray);
+ $this->prependchildren[] = new breadcrumb_navigation_node($itemarray);
return $this;
}
}
+/**
+ * Subclass of navigation_node allowing different rendering for the breadcrumbs
+ * in particular adding extra metadata for search engine robots to leverage.
+ *
+ * @package core
+ * @category navigation
+ * @copyright 2015 Brendan Heywood
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class breadcrumb_navigation_node extends navigation_node {
+
+ /**
+ * A proxy constructor
+ *
+ * @param mixed $navnode A navigation_node or an array
+ */
+ public function __construct($navnode) {
+ if (is_array($navnode)) {
+ parent::__construct($navnode);
+ } else if ($navnode instanceof navigation_node) {
+
+ // Just clone everything.
+ $objvalues = get_object_vars($navnode);
+ foreach ($objvalues as $key => $value) {
+ $this->$key = $value;
+ }
+ } else {
+ throw coding_exception('Not a valid breadcrumb_navigation_node');
+ }
+ }
+
+}
+
/**
* Class used to manage the settings option for the current page
*