Introduce Icinga\Web\Widget\Tab::$label as alternative for $title

This commit is contained in:
Johannes Meyer 2015-02-23 16:48:02 +01:00
parent 48286e0d59
commit 9fb3dcabea
1 changed files with 25 additions and 1 deletions

View File

@ -42,6 +42,8 @@ class Tab extends AbstractWidget
*/
private $title = '';
private $label = '';
/**
* The Url this tab points to
*
@ -116,6 +118,11 @@ class Tab extends AbstractWidget
return $this->name;
}
public function setLabel($label)
{
$this->label = $label;
}
/**
* @param mixed $title
*/
@ -210,9 +217,22 @@ class Tab extends AbstractWidget
if ($this->active) {
$classes[] = 'active';
}
$caption = $view->escape($this->title);
$caption = $view->escape($this->label);
$tagParams = $this->tagParams;
if ($this->title) {
if ($tagParams !== null) {
$tagParams['title'] = $this->title;
$tagParams['aria-label'] = $this->title;
} else {
$tagParams = array(
'title' => $this->title,
'aria-label' => $this->title
);
}
}
if ($this->icon !== null) {
if (strpos($this->icon, '.') === false) {
$caption = $view->icon($this->icon) . $caption;
@ -220,13 +240,16 @@ class Tab extends AbstractWidget
$caption = $view->img($this->icon, null, array('class' => 'icon')) . $caption;
}
}
if ($this->url !== null) {
$this->url->overwriteParams($this->urlParams);
if ($tagParams !== null) {
$params = $view->propertiesToString($tagParams);
} else {
$params = '';
}
$tab = sprintf(
'<a href="%s"%s>%s</a>',
$this->url,
@ -236,6 +259,7 @@ class Tab extends AbstractWidget
} else {
$tab = $caption;
}
$class = empty($classes) ? '' : sprintf(' class="%s"', implode(' ', $classes));
return '<li ' . $class . '>' . $tab . "</li>\n";
}