From aeb055b7d8aaa332308e9a74c3d4b59f3f388a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A1i=20Thi=C3=AAn=20V=C5=A9?= Date: Sun, 12 Jun 2022 05:56:51 +0700 Subject: [PATCH] New admin.list.extendRecords event (#989) --- app/admin/actions/ListController.php | 4 ++++ app/admin/traits/ListExtendable.php | 9 +++++++++ app/admin/widgets/Lists.php | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/app/admin/actions/ListController.php b/app/admin/actions/ListController.php index bb085d49ac..1a5dd81a40 100644 --- a/app/admin/actions/ListController.php +++ b/app/admin/actions/ListController.php @@ -199,6 +199,10 @@ public function makeList($alias) $this->controller->listExtendQuery($query, $alias); }); + $widget->bindEvent('list.extendRecords', function ($records) use ($alias) { + return $this->controller->listExtendRecords($records, $alias); + }); + $widget->bindEvent('list.overrideColumnValue', function ($record, $column, $value) use ($alias) { return $this->controller->listOverrideColumnValue($record, $column, $alias); }); diff --git a/app/admin/traits/ListExtendable.php b/app/admin/traits/ListExtendable.php index 0225542354..1f0038da20 100644 --- a/app/admin/traits/ListExtendable.php +++ b/app/admin/traits/ListExtendable.php @@ -51,6 +51,15 @@ public function listExtendQuery($query, $alias = null) { } + /** + * listExtendRecords controller override: Extend the records used for populating the list + * after the query is processed. + * @param Illuminate\Contracts\Pagination\LengthAwarePaginator|Illuminate\Database\Eloquent\Collection $records + */ + public function listExtendRecords($records, $alias = null) + { + } + /** * Controller override: Extend the query used for populating the filter * options before the default query is processed. diff --git a/app/admin/widgets/Lists.php b/app/admin/widgets/Lists.php index 1ff3107953..4847b54d62 100644 --- a/app/admin/widgets/Lists.php +++ b/app/admin/widgets/Lists.php @@ -410,6 +410,10 @@ protected function getRecords() $records = $model->get(); } + if ($event = $this->fireSystemEvent('admin.list.extendRecords', [&$records])) { + $records = $event; + } + return $this->records = $records; }