forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuBuilder.php
More file actions
35 lines (29 loc) · 1.05 KB
/
MenuBuilder.php
File metadata and controls
35 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace ProcessMaker\Managers;
use Lavary\Menu\Item;
class MenuBuilder extends \Lavary\Menu\Builder
{
/**
* Adds an item to the menu.
*
* @param string $title
* @param string|array $options
*
* @return Item $item
*/
public function add($title, $options = '')
{
$id = isset($options['id']) ? $options['id'] : $this->id();
$item = new Item($this, $id, $title, $options);
if (!empty($options['beforeItem']) && !empty($options['index'])) {
$beforeItem = $this->items->where('id', $options['beforeItem'])->first();
$this->items->splice($this->items->search($beforeItem) - $options['index'], 0, [$item]);
} elseif (!empty($options['afterItem']) && !empty($options['index'])) {
$afterItem = $this->items->where('id', $options['afterItem'])->first();
$this->items->splice($this->items->search($afterItem) + $options['index'], 0, [$item]);
} else {
$this->items->push($item);
}
return $item;
}
}