2012-12-07 22:32:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMenuView extends AphrontView {
|
|
|
|
|
|
|
|
private $items = array();
|
|
|
|
private $map = array();
|
2012-12-07 22:33:03 +01:00
|
|
|
private $classes = array();
|
|
|
|
|
|
|
|
public function addClass($class) {
|
|
|
|
$this->classes[] = $class;
|
|
|
|
return $this;
|
|
|
|
}
|
2012-12-07 22:32:14 +01:00
|
|
|
|
2012-12-07 22:34:44 +01:00
|
|
|
public function newLabel($name) {
|
|
|
|
$item = id(new PhabricatorMenuItemView())
|
|
|
|
->setType(PhabricatorMenuItemView::TYPE_LABEL)
|
|
|
|
->setName($name);
|
|
|
|
|
|
|
|
$this->addMenuItem($item);
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newLink($name, $href) {
|
|
|
|
$item = id(new PhabricatorMenuItemView())
|
|
|
|
->setType(PhabricatorMenuItemView::TYPE_LINK)
|
|
|
|
->setName($name)
|
|
|
|
->setHref($href);
|
|
|
|
|
|
|
|
$this->addMenuItem($item);
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:32:14 +01:00
|
|
|
public function addMenuItem(PhabricatorMenuItemView $item) {
|
|
|
|
$key = $item->getKey();
|
|
|
|
if ($key !== null) {
|
|
|
|
if (isset($this->map[$key])) {
|
|
|
|
throw new Exception(
|
|
|
|
"Menu contains duplicate items with key '{$key}'!");
|
|
|
|
}
|
|
|
|
$this->map[$key] = $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
$this->appendChild($item);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getItem($key) {
|
|
|
|
return idx($this->map, $key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getItems() {
|
|
|
|
return $this->items;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
2012-12-07 22:33:03 +01:00
|
|
|
$classes = $this->classes;
|
|
|
|
$classes[] = 'phabricator-menu-view';
|
|
|
|
|
2012-12-07 22:32:14 +01:00
|
|
|
return phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
2012-12-07 22:33:03 +01:00
|
|
|
'class' => implode(' ', $classes),
|
2012-12-07 22:32:14 +01:00
|
|
|
),
|
|
|
|
$this->renderChildren());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|