From a2a76675e4c8cc9a07c27f2c691020721120fc38 Mon Sep 17 00:00:00 2001 From: Jaap Jansma <jaap.jansma@civicoop.org> Date: Tue, 22 Oct 2019 11:49:13 +0200 Subject: [PATCH] Fixed notices and warnings --- Civi/FormProcessor/DataBag.php | 72 ++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/Civi/FormProcessor/DataBag.php b/Civi/FormProcessor/DataBag.php index a327317..9e8d12f 100644 --- a/Civi/FormProcessor/DataBag.php +++ b/Civi/FormProcessor/DataBag.php @@ -8,17 +8,17 @@ namespace Civi\FormProcessor; class DataBag { - + private $inputs = array(); - + private $actions = array(); - + private $inputData = array(); - + private $actionData = array(); /** * Sets the input data for a given input. - * + * * @param \CRM_FormProcessor_BAO_FormProcessorInput $inputObject * @param mixed $value * @return DataBag @@ -26,31 +26,31 @@ class DataBag { public function setInputData($inputObject, $value) { $this->inputs[$inputObject->id] = $inputObject; $this->inputData[$inputObject->id] = $value; - return $this; + return $this; } - - /** + + /** * Retrieves the input data for a given input. - * + * * @param $input * @return string */ public function getInputData($inputObject) { return $this->inputData[$inputObject->id]; } - + /** * Returns an array with all the inputs. - * + * * @return array */ public function getAllInputs() { return $this->inputs; } - + /** * Sets the action data for a given action. - * + * * @param $action * @param string $field * @return DataBag @@ -58,31 +58,34 @@ class DataBag { public function setActionData($actionObject, $field, $value) { $this->actions[$actionObject->id] = $actionObject; $this->actionData[$actionObject->name][$field] = $value; - return $this; + return $this; } - - /** + + /** * Retrieves all the action data for a given action. - * + * * @param $actionObject - * @return string + * @return array */ public function getActionData($actionObject) { - return $this->actionData[$actionObject->name]; + if (isset($this->actionData[$actionObject->name])) { + return $this->actionData[$actionObject->name]; + } + return array(); } - + /** * Returns an array with all the actions. - * + * * @return array */ public function getAllActions() { return $this->actions; } - + /** * Sets the action data from an action provider parameter bag object. - * + * * @param $actionObject * @param $parameterBag * @return DataBag @@ -94,16 +97,16 @@ class DataBag { } return $this; } - + /** * Returns the data by its alias. Returns null when the alias is not set - * + * * Example aliases: * input.email * action.3.contact_id - * + * * @param string - * @return mixed|null + * @return mixed|null */ public function getDataByAlias($alias) { $splitted_alias = explode(".", $alias); @@ -117,14 +120,14 @@ class DataBag { } return null; } - + /** * Returns all the aliases for data fields. - * + * * An alias looks like: * input.email * action.3.contact_id - * + * * @return array. */ public function getAllAliases() { @@ -133,13 +136,16 @@ class DataBag { $aliases[] = 'input.'.$input->name; } foreach($this->actions as $action) { + if (!isset($this->actionData[$action->name])) { + continue; + } foreach($this->actionData[$action->name] as $field => $value) { - $aliases[] = 'action.'.$action->name.'.'.$field; + $aliases[] = 'action.'.$action->name.'.'.$field; } } return $aliases; } - + /** * Returns the input object by its name. */ @@ -151,5 +157,5 @@ class DataBag { } return null; } - + } -- GitLab