diff options
Diffstat (limited to 'engine/classes')
-rw-r--r-- | engine/classes/ElggMenuBuilder.php | 19 | ||||
-rw-r--r-- | engine/classes/ElggMenuItem.php | 25 |
2 files changed, 43 insertions, 1 deletions
diff --git a/engine/classes/ElggMenuBuilder.php b/engine/classes/ElggMenuBuilder.php index f51ec8c62..33abc0c6b 100644 --- a/engine/classes/ElggMenuBuilder.php +++ b/engine/classes/ElggMenuBuilder.php @@ -179,9 +179,12 @@ class ElggMenuBuilder { case 'title': $sort_callback = array('ElggMenuBuilder', 'compareByTitle'); break; - case 'name'; + case 'name': $sort_callback = array('ElggMenuBuilder', 'compareByName'); break; + case 'weight': + $sort_callback = array('ElggMenuBuilder', 'compareByWeight'); + break; case 'order': // use registration order return; @@ -244,4 +247,18 @@ class ElggMenuBuilder { return strcmp($a, $b); } + + /** + * Compare two menu items by their weight + * + * @param ElggMenuItem $a + * @param ElggMenuItem $b + * @return bool + */ + public static function compareByWeight($a, $b) { + $a = $a->getWeight(); + $b = $b->getWeight(); + + return $a > $b; + } } diff --git a/engine/classes/ElggMenuItem.php b/engine/classes/ElggMenuItem.php index a190a89ef..108cb56f2 100644 --- a/engine/classes/ElggMenuItem.php +++ b/engine/classes/ElggMenuItem.php @@ -39,6 +39,11 @@ class ElggMenuItem { protected $tooltip = ''; /** + * @var int Menu weight - smaller weights float to the top + */ + protected $weight = 100; + + /** * @var bool Is this the currently selected menu item */ protected $selected = false; @@ -227,6 +232,26 @@ class ElggMenuItem { } /** + * Set the weight of the menu item + * + * @param int $weight The lower weight items float to the top of the menu + * + * @return void + */ + public function setWeight($weight) { + $this->weight = $weight; + } + + /** + * Get the weight of the menu item + * + * @return int + */ + public function getWeight() { + return $this->weight; + } + + /** * Set the section identifier * * @param string $section The identifier of the section |