Skip to content

Commit

Permalink
BaseItemList: Emit events before and after adding the list item to th…
Browse files Browse the repository at this point in the history
…e list
  • Loading branch information
raviks789 committed May 21, 2024
1 parent 0747a58 commit 0e02d30
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Common/BaseItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ 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';

public const BEFORE_ITEM_ADD = 'before-item-add';

/** @var array<string, mixed> */
protected $baseAttributes = [
'class' => ['item-list', 'default-layout'],
Expand Down Expand Up @@ -62,7 +67,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

0 comments on commit 0e02d30

Please sign in to comment.