From e8e9c1b2ed90338ac44ef6e1be4b3c9049978cc5 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Thu, 24 Oct 2024 13:30:54 +0200 Subject: [PATCH] BaseItemList: Add setter/getter to set empty state message --- src/Common/BaseItemList.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Common/BaseItemList.php b/src/Common/BaseItemList.php index 310621f4..bc523082 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 to show if 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 if the list is empty + * + * @return string + */ + public function getEmptyStateMessage(): string + { + if ($this->emptyStateMessage === null) { + return t('No items found.'); + } + + return $this->emptyStateMessage; + } + + /** + * Set message to show if the list is empty + * + * @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())); } } }