Skip to content

Commit 0e02d30

Browse files
committed
BaseItemList: Emit events before and after adding the list item to the list
1 parent 0747a58 commit 0e02d30

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Common/BaseItemList.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ abstract class BaseItemList extends BaseHtmlElement
1515
{
1616
use BaseFilter;
1717

18+
/** @var string Emitted while assembling the list after adding each list item */
19+
public const ON_ITEM_ADD = 'item-added';
20+
21+
public const BEFORE_ITEM_ADD = 'before-item-add';
22+
1823
/** @var array<string, mixed> */
1924
protected $baseAttributes = [
2025
'class' => ['item-list', 'default-layout'],
@@ -62,7 +67,9 @@ protected function assemble(): void
6267
foreach ($this->data as $data) {
6368
/** @var BaseListItem|BaseTableRowItem $item */
6469
$item = new $itemClass($data, $this);
70+
$this->emit(self::BEFORE_ITEM_ADD, [$item, $data]);
6571
$this->addHtml($item);
72+
$this->emit(self::ON_ITEM_ADD, [$item, $data]);
6673
}
6774

6875
if ($this->isEmpty()) {

0 commit comments

Comments
 (0)