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';
}
$this->firstAllowedAction = array_shift($allowedActions);
$this->getTabs()->setTitle($this->translate('Config Navigation'));
}
public function devtoolsAction()

View File

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