From 4c9af3b1ecc760d85433092446799c612dd385f1 Mon Sep 17 00:00:00 2001 From: Tobias Feijten Date: Thu, 16 Feb 2023 20:22:42 +0100 Subject: [PATCH] Fix execution order in ActionsBuilder --- Builder/Admin/ActionsBuilder.php | 14 ++++++++++---- Generator/Action/Object/DeleteAction.php | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Builder/Admin/ActionsBuilder.php b/Builder/Admin/ActionsBuilder.php index 9c5f5f92..225aa4f7 100644 --- a/Builder/Admin/ActionsBuilder.php +++ b/Builder/Admin/ActionsBuilder.php @@ -19,6 +19,12 @@ public function getYamlKey(): string public function getVariables(): array { + // Return empty array if the variables have not yet been set, + // to prevent calling getObjectActions or getBatchActions without reading the configuration + if (empty($this->variables)) { + return []; + } + // If credentials are not globally defined, // check if an action have credentials if (null === $this->getVariable('credentials')) { @@ -49,13 +55,13 @@ public function getBatchActions(): array protected function setUserBatchActionConfiguration(Action $action) { - $batchActions = $this->getVariable('batch_actions', array()); + $batchActions = $this->getVariable('batch_actions', []); $builderOptions = is_array($batchActions) && array_key_exists($action->getName(), $batchActions) ? $batchActions[$action->getName()] - : array(); + : []; $globalOptions = $this->getGenerator()->getFromYaml( - 'params.batch_actions.'.$action->getName(), array() + 'params.batch_actions.'.$action->getName(), [] ); if (null !== $builderOptions) { @@ -76,7 +82,7 @@ protected function addBatchAction(Action $action) protected function findBatchActions() { - $batchActions = $this->getVariable('batch_actions', array()); + $batchActions = $this->getVariable('batch_actions', []); foreach ($batchActions as $actionName => $actionParams) { $action = $this->findBatchAction($actionName); diff --git a/Generator/Action/Object/DeleteAction.php b/Generator/Action/Object/DeleteAction.php index dab30b2d..3dcb466d 100644 --- a/Generator/Action/Object/DeleteAction.php +++ b/Generator/Action/Object/DeleteAction.php @@ -24,10 +24,10 @@ public function __construct($name, BaseBuilder $builder) $this->setRoute($builder->getObjectActionsRoute()); - $this->setParams(array( + $this->setParams([ 'pk' => '{{ '.$builder->getModelClass().'.'.$builder->getModelPrimaryKeyName().' }}', 'action' => 'delete' - )); + ]); } }