Skip to content

Commit

Permalink
BaseItemList: Add setter/getter to set empty state message
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 authored and nilmerg committed Oct 24, 2024
1 parent e0918eb commit f449fa7
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Common/BaseItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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) {
Expand All @@ -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()));
}
}
}

0 comments on commit f449fa7

Please sign in to comment.