Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/Service/MappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ public function encodeArrayKeys(array $array, string $toReplace, string $replace

}//end encodeArrayKeys()

/**
* Renders a Twig template string using the mapping Twig environment.
*
* @param string $template The Twig template to render.
* @param array $context The context available inside the template.
*
* @return string The rendered template result.
* @throws LoaderError|SyntaxError Twig exceptions
*/
public function renderTemplateString(string $template, array $context = []): string
{
return html_entity_decode($this->twig->createTemplate($template)->render($context));
}

/**
* Maps (transforms) an array (input) to a different array (output).
*
Expand Down Expand Up @@ -150,7 +164,7 @@ public function executeMapping(Mapping $mapping, array $input, bool $list = fals
}

try {
$dotArray->set($key, html_entity_decode($this->twig->createTemplate($value)->render($originalInput)));
$dotArray->set($key, $this->renderTemplateString($value, $originalInput));
} catch (Throwable $e) {
throw new Exception("Error for mapping: {$mapping->getName()}, key: $key, value: $value and with message thrown: {$e->getMessage()}");
}
Expand Down
16 changes: 16 additions & 0 deletions lib/Service/SynchronizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SynchronizationService
const EXTRA_DATA_CONFIGS_LOCATION = 'extraDataConfigs';
const EXTRA_DATA_DYNAMIC_ENDPOINT_LOCATION = 'dynamicEndpointLocation';
const EXTRA_DATA_STATIC_ENDPOINT_LOCATION = 'staticEndpoint';
const EXTRA_DATA_ENDPOINT_TEMPLATE_LOCATION = 'endpointTemplate';
const KEY_FOR_EXTRA_DATA_LOCATION = 'keyToSetExtraData';
const MERGE_EXTRA_DATA_OBJECT_LOCATION = 'mergeExtraData';
const UNSET_CONFIG_KEY_LOCATION = 'unsetConfigKey';
Expand Down Expand Up @@ -1003,6 +1004,21 @@ private function fetchExtraDataForObject(
}
}

if (isset($extraDataConfig[$this::EXTRA_DATA_ENDPOINT_TEMPLATE_LOCATION]) === true
&& is_string($extraDataConfig[$this::EXTRA_DATA_ENDPOINT_TEMPLATE_LOCATION]) === true
&& $extraDataConfig[$this::EXTRA_DATA_ENDPOINT_TEMPLATE_LOCATION] !== ''
) {
$endpoint = $this->mappingService->renderTemplateString(
template: $extraDataConfig[$this::EXTRA_DATA_ENDPOINT_TEMPLATE_LOCATION],
context: [
'endpoint' => $endpoint ?? null,
'object' => $object,
'originId' => $originId,
'extraDataConfig' => $extraDataConfig,
]
);
}

if (!$endpoint) {
throw new Exception(
sprintf(
Expand Down
Loading