From 12471b10d716f31a6b1c6797d53ff250334298ba Mon Sep 17 00:00:00 2001 From: Lucas Correa Date: Thu, 6 May 2021 05:24:18 -0300 Subject: [PATCH] Add support to "serialize" option when set to true When the viewBuilder's "serialize" option is set to true, all the view variables are serialized. Some controllers classes can use this feature in your 'initialize' methods to avoid set up this option in all your actions. [1] - https://api.cakephp.org/4.2/class-Cake.View.JsonView.html [2] - https://api.cakephp.org/4.2/class-Cake.View.XmlView.html --- src/Controller/Component/ApiPaginationComponent.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Controller/Component/ApiPaginationComponent.php b/src/Controller/Component/ApiPaginationComponent.php index 8a4b938..34057a8 100644 --- a/src/Controller/Component/ApiPaginationComponent.php +++ b/src/Controller/Component/ApiPaginationComponent.php @@ -59,8 +59,11 @@ public function beforeRender(Event $event) $subject->set($config['key'], $this->pagingInfo); $data = $subject->viewBuilder()->getOption('serialize') ?? []; - $data[] = $config['key']; - $subject->viewBuilder()->setOption('serialize', $data); + + if (is_array($data)) { + $data[] = $config['key']; + $subject->viewBuilder()->setOption('serialize', $data); + } } /**