Skip to content

Commit 14dd9cc

Browse files
committed
Add setter/getter to set empty state message
1 parent e0918eb commit 14dd9cc

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Diff for: src/Common/BaseItemList.php

+32-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ abstract class BaseItemList extends BaseHtmlElement
3333

3434
protected $tag = 'ul';
3535

36+
/** @var ?string Message when the list is empty */
37+
protected $emptyStateMessage;
38+
3639
/**
3740
* Create a new item list
3841
*
@@ -76,6 +79,34 @@ protected function createListItem(object $data)
7679
return new $className($data, $this);
7780
}
7881

82+
/**
83+
* Get message to show for empty list
84+
*
85+
* @return string
86+
*/
87+
public function getEmptyStateMessage(): string
88+
{
89+
if ($this->emptyStateMessage === null) {
90+
return t('No items found.');
91+
}
92+
93+
return $this->emptyStateMessage;
94+
}
95+
96+
/**
97+
* Set message for empty list
98+
*
99+
* @param string $message
100+
*
101+
* @return $this
102+
*/
103+
public function setEmptyStateMessage(string $message): self
104+
{
105+
$this->emptyStateMessage = $message;
106+
107+
return $this;
108+
}
109+
79110
protected function assemble(): void
80111
{
81112
foreach ($this->data as $data) {
@@ -87,7 +118,7 @@ protected function assemble(): void
87118

88119
if ($this->isEmpty()) {
89120
$this->setTag('div');
90-
$this->addHtml(new EmptyStateBar(t('No items found.')));
121+
$this->addHtml(new EmptyStateBar($this->getEmptyStateMessage()));
91122
}
92123
}
93124
}

0 commit comments

Comments
 (0)