Header: Add header to tabs extension

refs #7976
This commit is contained in:
Marius Hein 2015-02-13 11:26:09 +01:00
parent 7839d50099
commit ce3a564de7
2 changed files with 57 additions and 5 deletions

View File

@ -66,6 +66,7 @@ class ConfigController extends ActionController
$allowedActions[] = 'roles'; $allowedActions[] = 'roles';
} }
$this->firstAllowedAction = array_shift($allowedActions); $this->firstAllowedAction = array_shift($allowedActions);
$this->getTabs()->setTitle($this->translate('Config Navigation'));
} }
public function devtoolsAction() public function devtoolsAction()

View File

@ -19,6 +19,7 @@ class Tabs extends AbstractWidget implements Countable
* @var string * @var string
*/ */
private $baseTpl = <<< 'EOT' private $baseTpl = <<< 'EOT'
{HEADER}
<ul class="tabs"> <ul class="tabs">
{TABS} {TABS}
{DROPDOWN} {DROPDOWN}
@ -26,6 +27,13 @@ class Tabs extends AbstractWidget implements Countable
</ul> </ul>
EOT; EOT;
/**
* Template used for the header
*
* @type string
*/
private $headerTpl = '<h2 class="sr-only">{TITLE}</h2>';
/** /**
* Template used for the tabs dropdown * Template used for the tabs dropdown
* *
@ -87,6 +95,13 @@ EOT;
*/ */
private $closeTab = true; private $closeTab = true;
/**
* Title of the tab navigation
*
* @type string
*/
private $title;
/** /**
* Set whether the current tab is closable * Set whether the current tab is closable
*/ */
@ -309,11 +324,21 @@ EOT;
} }
$close = $this->closeTab ? $this->renderCloseTab() : ''; $close = $this->closeTab ? $this->renderCloseTab() : '';
$html = $this->baseTpl; return str_replace(
$html = str_replace('{TABS}', $tabs, $html); array(
$html = str_replace('{DROPDOWN}', $drop, $html); '{TABS}',
$html = str_replace('{CLOSE}', $close, $html); '{DROPDOWN}',
return $html; '{CLOSE}',
'{HEADER}'
),
array(
$tabs,
$drop,
$close,
$this->renderHeader()
),
$this->baseTpl
);
} }
public function __toString() public function __toString()
@ -372,4 +397,30 @@ EOT;
$tabextension->apply($this); $tabextension->apply($this);
return $this; return $this;
} }
/**
* Set the title of the tab navigation
*
* @param string $title
* @return self
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Render the title into the header template
*
* @return string
*/
public function renderHeader()
{
if (! $this->title) {
return '';
}
return str_replace('{TITLE}', $this->title, $this->headerTpl);
}
} }