| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace Opentalent\OtTemplating\ViewHelpers\HelloAsso;
- use FluidTYPO3\Vhs\Traits\TemplateVariableViewHelperTrait;
- use Opentalent\OtCore\Exception\ApiRequestException;
- use Opentalent\OtCore\Logging\OtLogger;
- use Opentalent\OtCore\Service\OpentalentApiService;
- use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
- /**
- * This view helper returns the HelloAsso form's URL for the given event
- *
- * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
- *
- * <ot:helloAsso.getFormUrlByEventId as="form" eventId="1">
- * <f:debug>{form}</f:debug>
- * </ot:helloAsso.getFormUrlByEventId>
- *
- * @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 "<error>";
- }
- $variables = [$as => $form];
- return $this->renderChildrenWithVariables($variables);
- }
- }
|