diff --git a/Civi/FormProcessor/API/Provider.php b/Civi/FormProcessor/API/Provider.php index e2e364f2091c35444ec911e264ec4593c22df7b8..9840c061ba59b6c37084da45168052a11a190e20 100644 --- a/Civi/FormProcessor/API/Provider.php +++ b/Civi/FormProcessor/API/Provider.php @@ -144,8 +144,7 @@ $objAction->copyValues($action); // Create a parameter bag for the action - $parameterBag = $dataBag->convertToActionProviderParameterBag($actionProvider); - $mappedParameterBag = $actionProvider->createdMappedParameterBag($parameterBag, $action['mapping']); + $mappedParameterBag = $this->convertDataBagToMappedParameterBag($dataBag, $action['mapping'], $actionProvider); $outputBag = $action['type']->execute($mappedParameterBag); // Add the output of the action to the data bag of this action. $dataBag->setActionDataFromActionProviderParameterBag($objAction, $outputBag); @@ -154,6 +153,24 @@ return $formProcessor['output_handler']->handle($dataBag); } + /** + * Converts a DataBag object to a mapped parameterBag. + * + * @param DataBag $dataBag + * @param array $mapping + * @param $actionProvider + * @return ParameterBag; + */ + protected function convertDataBagToMappedParameterBag(DataBag $dataBag, $mapping, $actionProvider) { + $parameterBag = $actionProvider->createParameterBag(); + $fields = $dataBag->getAllAliases(); + foreach($fields as $field) { + $parameterBag->setParameter($field, $dataBag->getDataByAlias($field)); + } + $mappedParameterBag = $actionProvider->createdMappedParameterBag($parameterBag, $mapping); + return $mappedParameterBag; + } + /** * @param int $version * API version. diff --git a/Civi/FormProcessor/DataBag.php b/Civi/FormProcessor/DataBag.php index 6e34560c9b4fff2a38fe4b6e6cf8f0901e5f7bf7..194dc50757b37bb2e2d044baeb5dc6e9e5612378 100644 --- a/Civi/FormProcessor/DataBag.php +++ b/Civi/FormProcessor/DataBag.php @@ -107,7 +107,10 @@ class DataBag { public function getDataByAlias($alias) { $splitted_alias = explode(".", $alias); if ($splitted_alias[0] == 'input') { - return $this->inputData[$splitted_alias[1]]; + $input = $this->getInputByName($splitted_alias[1]); + if ($input) { + return $this->inputData[$input->id]; + } } elseif ($splitted_alias[0] == 'action') { return $this->actionData[$splitted_alias[1]][$splitted_alias[2]]; } @@ -115,20 +118,37 @@ class DataBag { } /** - * Convert this data bag to the action provider parameter bag. + * Returns all the aliases for data fields. + * + * An alias looks like: + * input.email + * action.3.contact_id + * + * @return array. */ - public function convertToActionProviderParameterBag($actionProvider) { - $parameterBag = $actionProvider->createParameterBag(); + public function getAllAliases() { + $aliases = array(); foreach($this->inputs as $input) { - $parameterBag->setParameter('input.'.$input->name, $this->inputData[$input->id]); + $aliases[] = 'input.'.$input->name; } foreach($this->actions as $action) { foreach($this->actionData[$action->id] as $field => $value) { - $outputParameterName = 'action.'.$action->id.'.'.$field; - $parameterBag->setParameter($outputParameterName, $value); + $aliases[] = 'action.'.$action->id.'.'.$field; } } - return $parameterBag; + return $aliases; + } + + /** + * Returns the input object by its name. + */ + private function getInputByName($name) { + foreach($this->inputs as $input) { + if ($input->name == $name) { + return $input; + } + } + return null; } } diff --git a/Civi/FormProcessor/OutputHandler/FormatOutput.php b/Civi/FormProcessor/OutputHandler/FormatOutput.php index 2fc8f21c1e0fb478f21ed96b54b2376334a1a46c..17065a45b67f0569cd5f146dd642f436f3e8dd0b 100644 --- a/Civi/FormProcessor/OutputHandler/FormatOutput.php +++ b/Civi/FormProcessor/OutputHandler/FormatOutput.php @@ -71,7 +71,7 @@ * @return string */ public function getLabel() { - return E::ts('Formal output'); + return E::ts('Formatted output'); } } \ No newline at end of file