* {form}
*
*
* @package Opentalent\OtTemplating\ViewHelpers
*/
class GetFormUrlByEventIdViewHelper extends OtAbstractViewHelper {
use TemplateVariableViewHelperTrait;
/**
* >> Required to prevent typo3 to escape the html output
* @var boolean
*/
protected $escapeOutput = false;
/**
* @var OpentalentApiService
*/
protected OpentalentApiService $opentalentApiService;
public function injectOpentalentApiService(OpentalentApiService $opentalentApiService) {
$this->opentalentApiService = $opentalentApiService;
}
/**
* -- This method is expected by Fluid --
* Declares the viewhelper's parameters
*/
public function initializeArguments()
{
$this->registerArgument(
'as',
'string',
'Name of the returned array',
true
);
$this->registerArgument(
'eventId',
'integer',
'Id of the event',
true
);
}
/**
* -- This method is expected by Fluid --
* Renders the content as html
*
* @return string
* @throws ApiRequestException
*/
public function render()
{
$as = $this->arguments['as'];
$eventId = $this->arguments['eventId'];
$uri = $this->opentalentApiService->getApiUri(
'api/public/helloasso/form/by-event/'.$eventId,
false,
true
);
try {
$form = $this->opentalentApiService->getJsonDecoded($uri);
} catch (ApiRequestException $e) {
OtLogger::error(sprintf('API Error: %s', $e->getMessage()));
return "";
}
$variables = [$as => $form];
return $this->renderChildrenWithVariables($variables);
}
}