2012-12-07 22:32:14 +01:00
|
|
|
<?php
|
|
|
|
|
2013-01-16 19:50:41 +01:00
|
|
|
final class PhabricatorMenuItemView extends AphrontTagView {
|
2012-12-07 22:32:14 +01:00
|
|
|
|
|
|
|
const TYPE_LINK = 'type-link';
|
|
|
|
const TYPE_SPACER = 'type-spacer';
|
|
|
|
const TYPE_LABEL = 'type-label';
|
2013-01-29 19:20:17 +01:00
|
|
|
const TYPE_BUTTON = 'type-button';
|
2013-02-03 19:02:35 +01:00
|
|
|
const TYPE_CUSTOM = 'type-custom';
|
2012-12-07 22:32:14 +01:00
|
|
|
|
|
|
|
private $name;
|
|
|
|
private $href;
|
|
|
|
private $type = self::TYPE_LINK;
|
|
|
|
private $isExternal;
|
|
|
|
private $key;
|
2012-12-07 22:33:03 +01:00
|
|
|
private $icon;
|
|
|
|
private $selected;
|
2013-01-16 18:00:11 +01:00
|
|
|
|
|
|
|
public function setProperty($property) {
|
|
|
|
$this->property = $property;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProperty() {
|
|
|
|
return $this->property;
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:33:03 +01:00
|
|
|
public function setSelected($selected) {
|
|
|
|
$this->selected = $selected;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSelected() {
|
|
|
|
return $this->selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setIcon($icon) {
|
|
|
|
$this->icon = $icon;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIcon() {
|
|
|
|
return $this->icon;
|
|
|
|
}
|
2012-12-07 22:32:14 +01:00
|
|
|
|
|
|
|
public function setKey($key) {
|
2012-12-07 22:35:17 +01:00
|
|
|
$this->key = (string)$key;
|
2012-12-07 22:32:14 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getKey() {
|
|
|
|
return $this->key;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setType($type) {
|
|
|
|
$this->type = $type;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getType() {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setHref($href) {
|
|
|
|
$this->href = $href;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHref() {
|
|
|
|
return $this->href;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setIsExternal($is_external) {
|
|
|
|
$this->isExternal = $is_external;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIsExternal() {
|
|
|
|
return $this->isExternal;
|
|
|
|
}
|
|
|
|
|
2013-01-16 19:50:41 +01:00
|
|
|
protected function getTagName() {
|
|
|
|
return $this->href ? 'a' : 'div';
|
|
|
|
}
|
2012-12-07 22:32:14 +01:00
|
|
|
|
2013-01-16 19:50:41 +01:00
|
|
|
protected function getTagAttributes() {
|
|
|
|
return array(
|
|
|
|
'class' => array(
|
|
|
|
'phabricator-menu-item-view',
|
|
|
|
'phabricator-menu-item-'.$this->type,
|
|
|
|
),
|
|
|
|
'href' => $this->href,
|
|
|
|
);
|
|
|
|
}
|
2012-12-07 22:32:14 +01:00
|
|
|
|
2013-01-16 19:50:41 +01:00
|
|
|
protected function getTagContent() {
|
2012-12-07 22:33:03 +01:00
|
|
|
$name = null;
|
2013-03-30 22:46:02 +01:00
|
|
|
$icon = null;
|
|
|
|
|
2012-12-07 22:33:03 +01:00
|
|
|
if ($this->name) {
|
2013-03-30 22:46:02 +01:00
|
|
|
|
2012-12-07 22:33:03 +01:00
|
|
|
$external = null;
|
|
|
|
if ($this->isExternal) {
|
|
|
|
$external = " \xE2\x86\x97";
|
|
|
|
}
|
2013-03-30 22:46:02 +01:00
|
|
|
|
|
|
|
if ($this->icon) {
|
|
|
|
require_celerity_resource('sprite-icon-css');
|
|
|
|
$icon = phutil_tag(
|
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-menu-item-icon sprite-icon '.
|
|
|
|
'action-'.$this->icon,
|
|
|
|
),
|
|
|
|
'');
|
|
|
|
}
|
|
|
|
|
2013-01-18 03:43:35 +01:00
|
|
|
$name = phutil_tag(
|
2012-12-07 22:33:03 +01:00
|
|
|
'span',
|
|
|
|
array(
|
|
|
|
'class' => 'phabricator-menu-item-name',
|
|
|
|
),
|
2013-03-09 22:52:41 +01:00
|
|
|
array(
|
|
|
|
$this->name,
|
|
|
|
$external,
|
|
|
|
));
|
2012-12-07 22:33:03 +01:00
|
|
|
}
|
|
|
|
|
2013-03-09 22:52:41 +01:00
|
|
|
return array(
|
2013-03-30 22:46:02 +01:00
|
|
|
$icon,
|
2013-03-09 22:52:41 +01:00
|
|
|
$this->renderChildren(),
|
|
|
|
$name,
|
|
|
|
);
|
2012-12-07 22:32:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|