Skip to content

Commit

Permalink
Missing piece of logic that was making quite unintuitive to add new m…
Browse files Browse the repository at this point in the history
…enus

Signed-off-by: emanuele <emanuele45@gmail.com>
  • Loading branch information
emanuele45 committed Nov 30, 2013
1 parent 2268f07 commit 4c1aa6f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
28 changes: 28 additions & 0 deletions sources/Positioning.class.php
Expand Up @@ -32,6 +32,13 @@ abstract class Positioning_Items
*/
protected $_position = null;

/**
* An (unique) id to identify the "item"
*
* @var string
*/
protected $_name = null;

/**
* Known positions the item can be added
*
Expand Down Expand Up @@ -231,6 +238,27 @@ public function childOf($parent)
return $this;
}

public function get($name)
{
// First the easy ones
if ($this->_name === $name)
return $this;

// If not, then let's have some fun
if (!empty($this->_children))
{
foreach ($this->_children as $key => $item)
{
$found = $item->get($name);

if ($found)
return $found;
}
}

return false;
}

/**
* Remove a item by name
*
Expand Down
13 changes: 8 additions & 5 deletions sources/subs/Menu.subs.php
Expand Up @@ -25,6 +25,11 @@
*/
class Menu_Entries extends Positioning_Items
{
public function __construct($id)
{
parent::__construct($id);
}

/**
* Add a new item to the pile
*
Expand Down Expand Up @@ -60,7 +65,7 @@ public function add($key, $item = null, $priority = null)
elseif ($this->_position === 'child')
{
if (!isset($this->_children[$this->_relative]))
$this->_children[$this->_relative] = new Menu_Entries();
$this->_children[$this->_relative] = new Menu_Entries($key);

// Always return the valid children of the "current" position
return $this->_children[$this->_relative];
Expand Down Expand Up @@ -111,7 +116,7 @@ class Standard_Menu extends Menu_Entries
public function get($id)
{
if (!isset($this->_instances[$id]))
$this->_instances[$id] = new Menu_Entries();
$this->_instances[$id] = new Menu_Entries($id);

return $this->_instances[$id];
}
Expand Down Expand Up @@ -159,9 +164,7 @@ public function createMenu($id, $menuOptions = array())
if (isset($subbutton['children']))
{
foreach ($subbutton['children']->prepareContext() as $key2 => $subbutton2)
{
$button['areas'][$key]['subsections'][$key2] = $subbutton2;
}
}
}
}
Expand Down Expand Up @@ -196,7 +199,7 @@ public static function context()

// this is a singleton
if ($instance === null)
$instance = new Standard_Menu();
$instance = new Standard_Menu('AllMenus');

return $instance;
}
Expand Down

0 comments on commit 4c1aa6f

Please sign in to comment.