From 451321400a77bb937acb99c4cddeacf5e4e409f8 Mon Sep 17 00:00:00 2001 From: julian_phronesys Date: Wed, 24 Aug 2022 17:00:53 +0200 Subject: [PATCH 1/3] added custom link formatter --- src/Datatables.php | 1 + src/View/Helper/DatatableHelper.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Datatables.php b/src/Datatables.php index 5c59384..87d3c57 100644 --- a/src/Datatables.php +++ b/src/Datatables.php @@ -9,6 +9,7 @@ class Datatables public const LINK_TYPE_POST = 'POST'; public const LINK_TYPE_PUT = 'PUT'; public const LINK_TYPE_DELETE = 'DELETE'; + public const LINK_TYPE_CUSTOM = 'CUSTOM'; public static function postLinkMethods() { diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index aca54c5..4b34efb 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -669,7 +669,12 @@ protected function processActionLink(array $link): string case Datatables::LINK_TYPE_POST: $output = new \CakeDC\Datatables\View\Formatter\Link\PostLink($this, $link); break; - + case Datatables::LINK_TYPE_CUSTOM: + if (empty($link['formatter'])) { + throw new \OutOfBoundsException("please specify a custom formatter"); + } + $output = new $link['formatter']($this,$link); + break; case Datatables::LINK_TYPE_GET: default: $output = new \CakeDC\Datatables\View\Formatter\Link\Link($this, $link); From 7a00ef7aa1e38d2fb08c61925ad0548f5c04abc1 Mon Sep 17 00:00:00 2001 From: julian_phronesys <38523433+JulianDroog@users.noreply.github.com> Date: Thu, 1 Sep 2022 11:08:43 +0200 Subject: [PATCH 2/3] Changed checks, update exception string --- src/View/Helper/DatatableHelper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index 4b34efb..527f1bb 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -670,10 +670,15 @@ protected function processActionLink(array $link): string $output = new \CakeDC\Datatables\View\Formatter\Link\PostLink($this, $link); break; case Datatables::LINK_TYPE_CUSTOM: - if (empty($link['formatter'])) { - throw new \OutOfBoundsException("please specify a custom formatter"); + if (!is_callable($link['formatter'] ?? null)) { + throw new \OutOfBoundsException("Please specify a custom formatter"); } $output = new $link['formatter']($this,$link); + + if (method_exists($output, 'link')){ + throw new \OutOfBoundsException("Method link is not found in class"); + } + break; case Datatables::LINK_TYPE_GET: default: From ca75091a50e9ffcdc0caeae3dd4a59f92b34d24b Mon Sep 17 00:00:00 2001 From: julian_phronesys <38523433+JulianDroog@users.noreply.github.com> Date: Thu, 1 Sep 2022 11:29:34 +0200 Subject: [PATCH 3/3] added '!' to method exists check --- src/View/Helper/DatatableHelper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/View/Helper/DatatableHelper.php b/src/View/Helper/DatatableHelper.php index 527f1bb..fffd815 100644 --- a/src/View/Helper/DatatableHelper.php +++ b/src/View/Helper/DatatableHelper.php @@ -675,10 +675,10 @@ protected function processActionLink(array $link): string } $output = new $link['formatter']($this,$link); - if (method_exists($output, 'link')){ + if (!method_exists($output, 'link')){ throw new \OutOfBoundsException("Method link is not found in class"); } - + break; case Datatables::LINK_TYPE_GET: default: