diff --git a/src/Common/BaseItemList.php b/src/Common/BaseItemList.php index 310621f4..abaa39e3 100644 --- a/src/Common/BaseItemList.php +++ b/src/Common/BaseItemList.php @@ -33,6 +33,9 @@ abstract class BaseItemList extends BaseHtmlElement protected $tag = 'ul'; + /** @var ?string Message when the list is empty */ + protected $emptyStateMessage; + /** * Create a new item list * @@ -76,6 +79,34 @@ protected function createListItem(object $data) return new $className($data, $this); } + /** + * Get message to show for empty list + * + * @return string + */ + public function getEmptyStateMessage(): string + { + if ($this->emptyStateMessage === null) { + return t('No items found.'); + } + + return $this->emptyStateMessage; + } + + /** + * Set message for empty list + * + * @param string $message + * + * @return $this + */ + public function setEmptyStateMessage(string $message): self + { + $this->emptyStateMessage = $message; + + return $this; + } + protected function assemble(): void { foreach ($this->data as $data) { @@ -87,7 +118,7 @@ protected function assemble(): void if ($this->isEmpty()) { $this->setTag('div'); - $this->addHtml(new EmptyStateBar(t('No items found.'))); + $this->addHtml(new EmptyStateBar($this->getEmptyStateMessage())); } } }