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: Emit events before and after adding the list item to the list #217

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions asset/css/list/list-item.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
&:hover {
color: @list-item-title-hover-color;
text-decoration: none;

.subject {
color: @list-item-title-hover-color;
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Common/BaseItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ abstract class BaseItemList extends BaseHtmlElement
{
use BaseFilter;

/** @var string Emitted while assembling the list after adding each list item */
public const ON_ITEM_ADD = 'item-added';

/** @var string Emitted while assembling the list before adding each list item */
public const BEFORE_ITEM_ADD = 'before-item-add';
nilmerg marked this conversation as resolved.
Show resolved Hide resolved

/** @var array<string, mixed> */
protected $baseAttributes = [
'class' => ['item-list', 'default-layout'],
Expand Down Expand Up @@ -62,7 +68,9 @@ protected function assemble(): void
foreach ($this->data as $data) {
/** @var BaseListItem|BaseTableRowItem $item */
$item = new $itemClass($data, $this);
$this->emit(self::BEFORE_ITEM_ADD, [$item, $data]);
$this->addHtml($item);
$this->emit(self::ON_ITEM_ADD, [$item, $data]);
}

if ($this->isEmpty()) {
Expand Down
Loading