Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseItemList: Add setter/getter to set empty state message #234

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

protected $tag = 'ul';

/** @var ?string Message to show if the list is empty */
protected $emptyStateMessage;

/**
* Create a new item list
*
Expand Down Expand Up @@ -73,13 +76,41 @@
{
$className = $this->getItemClass();

return new $className($data, $this);

Check failure on line 79 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Method ipl\Web\Common\BaseItemList::createListItem() should return ipl\Web\Common\BaseListItem|ipl\Web\Common\BaseTableRowItem but returns object.

Check failure on line 79 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.1 on ubuntu-latest

Method ipl\Web\Common\BaseItemList::createListItem() should return ipl\Web\Common\BaseListItem|ipl\Web\Common\BaseTableRowItem but returns object.

Check failure on line 79 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

Method ipl\Web\Common\BaseItemList::createListItem() should return ipl\Web\Common\BaseListItem|ipl\Web\Common\BaseTableRowItem but returns object.

Check failure on line 79 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Method ipl\Web\Common\BaseItemList::createListItem() should return ipl\Web\Common\BaseListItem|ipl\Web\Common\BaseTableRowItem but returns object.

Check failure on line 79 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Method ipl\Web\Common\BaseItemList::createListItem() should return ipl\Web\Common\BaseListItem|ipl\Web\Common\BaseTableRowItem but returns object.

Check failure on line 79 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

Method ipl\Web\Common\BaseItemList::createListItem() should return ipl\Web\Common\BaseListItem|ipl\Web\Common\BaseTableRowItem but returns object.

Check failure on line 79 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.0 on ubuntu-latest

Method ipl\Web\Common\BaseItemList::createListItem() should return ipl\Web\Common\BaseListItem|ipl\Web\Common\BaseTableRowItem but returns object.
}

/**
* 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) {
$item = $this->createListItem($data);

Check failure on line 113 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Parameter #1 $data of method ipl\Web\Common\BaseItemList::createListItem() expects object, mixed given.

Check failure on line 113 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.1 on ubuntu-latest

Parameter #1 $data of method ipl\Web\Common\BaseItemList::createListItem() expects object, mixed given.

Check failure on line 113 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

Parameter #1 $data of method ipl\Web\Common\BaseItemList::createListItem() expects object, mixed given.

Check failure on line 113 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Parameter #1 $data of method ipl\Web\Common\BaseItemList::createListItem() expects object, mixed given.

Check failure on line 113 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Parameter #1 $data of method ipl\Web\Common\BaseItemList::createListItem() expects object, mixed given.

Check failure on line 113 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

Parameter #1 $data of method ipl\Web\Common\BaseItemList::createListItem() expects object, mixed given.

Check failure on line 113 in src/Common/BaseItemList.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.0 on ubuntu-latest

Parameter #1 $data of method ipl\Web\Common\BaseItemList::createListItem() expects object, mixed given.
$this->emit(self::BEFORE_ITEM_ADD, [$item, $data]);
$this->addHtml($item);
$this->emit(self::ON_ITEM_ADD, [$item, $data]);
Expand All @@ -87,7 +118,7 @@

if ($this->isEmpty()) {
$this->setTag('div');
$this->addHtml(new EmptyStateBar(t('No items found.')));
$this->addHtml(new EmptyStateBar($this->getEmptyStateMessage()));
}
}
}
Loading