From 09afc04a0994a1f4a5ce4f15bb8421531b4e9200 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Thu, 19 Sep 2024 16:11:05 +0200 Subject: [PATCH] Fetch item class for each row of the data --- src/Common/BaseItemList.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Common/BaseItemList.php b/src/Common/BaseItemList.php index 8320d1c1..310621f4 100644 --- a/src/Common/BaseItemList.php +++ b/src/Common/BaseItemList.php @@ -62,12 +62,24 @@ protected function init(): void { } + /** + * Create a list item for the given data + * + * @param object $data + * + * @return BaseListItem|BaseTableRowItem + */ + protected function createListItem(object $data) + { + $className = $this->getItemClass(); + + return new $className($data, $this); + } + protected function assemble(): void { - $itemClass = $this->getItemClass(); foreach ($this->data as $data) { - /** @var BaseListItem|BaseTableRowItem $item */ - $item = new $itemClass($data, $this); + $item = $this->createListItem($data); $this->emit(self::BEFORE_ITEM_ADD, [$item, $data]); $this->addHtml($item); $this->emit(self::ON_ITEM_ADD, [$item, $data]);