3 final class PHUITabGroupView
extends AphrontTagView
{
5 private $tabs = array();
9 private $hideSingleTab;
11 protected function canAppendChild() {
15 public function setVertical($vertical) {
16 $this->vertical
= $vertical;
20 public function getVertical() {
21 return $this->vertical
;
24 public function setHideSingleTab($hide_single_tab) {
25 $this->hideSingleTab
= $hide_single_tab;
29 public function getHideSingleTab() {
30 return $this->hideSingleTab
;
33 public function addTab(PHUITabView
$tab) {
34 $key = $tab->getKey();
37 if (isset($this->tabs
[$key])) {
40 'Each tab in a tab group must have a unique key; attempting to add '.
41 'a second tab with a duplicate key ("%s").',
45 $this->tabs
[$key] = $tab;
50 public function selectTab($key) {
51 if (empty($this->tabs
[$key])) {
54 'Unable to select tab ("%s") which does not exist.',
58 $this->selectedTab
= $key;
63 public function getSelectedTabKey() {
68 if ($this->selectedTab
!== null) {
69 return $this->selectedTab
;
72 return head($this->tabs
)->getKey();
75 protected function getTagAttributes() {
76 $tab_map = mpull($this->tabs
, 'getContentID', 'getKey');
79 if ($this->getVertical()) {
80 $classes[] = 'phui-tab-group-view-vertical';
85 'sigil' => 'phui-tab-group-view',
92 protected function getTagContent() {
93 Javelin
::initBehavior('phui-tab-group');
95 $tabs = new PHUIListView();
97 if ($this->getVertical()) {
98 $tabs->setType(PHUIListView
::NAVBAR_VERTICAL
);
100 $tabs->setType(PHUIListView
::NAVBAR_LIST
);
105 $selected_tab = $this->getSelectedTabKey();
106 foreach ($this->tabs
as $tab) {
107 $item = $tab->newMenuItem();
108 $tab_key = $tab->getKey();
110 if ($tab_key == $selected_tab) {
111 $item->setSelected(true);
114 $style = 'display: none;';
117 $tabs->addMenuItem($item);
119 $content[] = javelin_tag(
123 'id' => $tab->getContentID(),
128 if ($this->hideSingleTab
&& (count($this->tabs
) == 1)) {
132 if ($tabs && $this->getVertical()) {
133 $content = phutil_tag(
136 'style' => 'width: 100%',
148 'class' => 'phui-tab-group-view-tab-column',