diff --git a/library/Icingadb/Widget/ItemTable/StateItemTable.php b/library/Icingadb/Widget/ItemTable/StateItemTable.php index 251ed7c4..b128c8ff 100644 --- a/library/Icingadb/Widget/ItemTable/StateItemTable.php +++ b/library/Icingadb/Widget/ItemTable/StateItemTable.php @@ -10,6 +10,9 @@ use ipl\Html\Form; use ipl\Html\Html; use ipl\Html\HtmlElement; use ipl\Html\HtmlString; +use ipl\Html\Text; +use ipl\Html\ValidHtml; +use ipl\I18n\Translation; use ipl\Orm\Common\SortUtil; use ipl\Orm\Query; use ipl\Web\Control\SortControl; @@ -19,6 +22,8 @@ use ipl\Web\Widget\Icon; /** @todo Figure out what this might (should) have in common with the new ItemTable implementation */ abstract class StateItemTable extends BaseHtmlElement { + use Translation; + protected $baseAttributes = [ 'class' => 'state-item-table' ]; @@ -34,6 +39,9 @@ abstract class StateItemTable extends BaseHtmlElement protected $tag = 'table'; + /** @var ?ValidHtml Message to show if the list is empty */ + protected $emptyStateMessage; + /** * Create a new item table * @@ -59,6 +67,38 @@ abstract class StateItemTable extends BaseHtmlElement { } + /** + * Get message to show if the list is empty + * + * @return ValidHtml + */ + public function getEmptyStateMessage(): ValidHtml + { + if ($this->emptyStateMessage === null) { + return new Text($this->translate('No items found.')); + } + + return $this->emptyStateMessage; + } + + /** + * Set message to show if the list is empty + * + * @param mixed $message If empty, the default message is used + * + * @return $this + */ + public function setEmptyStateMessage($message): self + { + if (empty($message)) { + $this->emptyStateMessage = null; + } else { + $this->emptyStateMessage = Html::wantHtml($message); + } + + return $this; + } + /** * Get the columns being rendered * @@ -89,7 +129,7 @@ abstract class StateItemTable extends BaseHtmlElement protected function getVisualLabel() { - return new Icon('heartbeat', ['title' => t('Severity')]); + return new Icon('heartbeat', ['title' => $this->translate('Severity')]); } protected function assembleColumnHeader(BaseHtmlElement $header, string $name, $label): void @@ -186,8 +226,8 @@ abstract class StateItemTable extends BaseHtmlElement null, new HtmlElement( 'td', - Attributes::create(['colspan' => count($this->columns)]), - new EmptyStateBar(t('No items found.')) + Attributes::create(['colspan' => count($this->columns) + 1]), + new EmptyStateBar($this->getEmptyStateMessage()) ) )); }