aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/classes/ElggMenuItem.php61
-rw-r--r--views/default/navigation/menu/elements/item.php19
2 files changed, 75 insertions, 5 deletions
diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php
index 108cb56f2..0de5feddb 100644
--- a/engine/classes/ElggMenuItem.php
+++ b/engine/classes/ElggMenuItem.php
@@ -24,6 +24,16 @@ class ElggMenuItem {
protected $url = null;
/**
+ * @var array Classes to apply to the anchor tag.
+ */
+ protected $linkClass = array();
+
+ /**
+ * @var array Classes to apply to the li tag.
+ */
+ protected $itemClass = array();
+
+ /**
* @var array Page context array
*/
protected $contexts = array('all');
@@ -232,6 +242,54 @@ class ElggMenuItem {
}
/**
+ * Set the anchor class
+ *
+ * @param mixed $class An array of class names, or a single string class name.
+ *
+ * @return void
+ */
+ public function setLinkClass($class) {
+ if (!is_array($class)) {
+ $this->linkClass[] = $class;
+ } else {
+ $this->linkClass = $class;
+ }
+ }
+
+ /**
+ * Get the anchor classes as text
+ *
+ * @return string
+ */
+ public function getLinkClass() {
+ return implode(' ', $this->linkClass);
+ }
+
+ /**
+ * Set the li classes
+ *
+ * @param mixed $class An array of class names, or a single string class name.
+ *
+ * @return void
+ */
+ public function setItemClass($class) {
+ if (!is_array($class)) {
+ $this->itemClass[] = $class;
+ } else {
+ $this->itemClass = $class;
+ }
+ }
+
+ /**
+ * Get the li classes as text
+ *
+ * @return string
+ */
+ public function getItemClass() {
+ return implode(' ', $this->itemClass);
+ }
+
+ /**
* Set the weight of the menu item
*
* @param int $weight The lower weight items float to the top of the menu
@@ -354,6 +412,9 @@ class ElggMenuItem {
if ($this->url) {
$vars['href'] = $this->url;
}
+ if ($this->linkClass) {
+ $vars['class'] = $this->linkClass;
+ }
return elgg_view('output/url', $vars);
}
diff --git a/views/default/navigation/menu/elements/item.php b/views/default/navigation/menu/elements/item.php
index 5a9a8743d..7b07c9485 100644
--- a/views/default/navigation/menu/elements/item.php
+++ b/views/default/navigation/menu/elements/item.php
@@ -1,19 +1,28 @@
<?php
+/**
+ * A single element of a menu.
+ *
+ * @package Elgg.Core
+ * @subpackage Navigation
+ */
$item = $vars['item'];
-$class = '';
$link_class = 'elgg-menu-closed';
if ($item->getSelected()) {
- $class = 'class="elgg-state-selected"';
+ $item->setItemClass('elgg-state-selected');
$link_class = 'elgg-menu-opened';
}
-$link_vars = array();
-
$children = $item->getChildren();
if ($children) {
- $link_vars['class'] = "elgg-menu-parent $link_class";
+ $item->setLinkClass($link_class);
+ $item->setLinkClass('elgg-menu-parent');
+}
+
+$item_class = $item->getItemClass();
+if ($item_class) {
+ $class = "class=\"$item_class\"";
}
echo "<li $class>";