浏览代码

Adds HelloAsso form integration

Enables embedding HelloAsso forms into content.

This commit introduces a new content element that allows
editors to embed HelloAsso forms by specifying the event ID.
It fetches the form URL from the Opentalent API and renders
it within an iframe.
Olivier Massot 2 月之前
父节点
当前提交
489bfd816b

+ 7 - 2
ot_core/Classes/Service/OpentalentApiService.php

@@ -60,9 +60,14 @@ class OpentalentApiService
      * @param bool $public Si vrai, retourne l'url publique et non interne
      * @return string
      */
-    public function getApiUri(string $trailing_part = "", bool $public = false): string
+    public function getApiUri(string $trailing_part = "", bool $public = false, bool $v2 = false): string
     {
-        $uri = OpentalentEnvService::get($public ? 'PUBLIC_API_BASE_URI' : 'API_BASE_URI');
+        if ($v2) {
+            $uri = OpentalentEnvService::get($public ? 'PUBLIC_AP2I_BASE_URI' : 'AP2I_BASE_URI');
+        } else {
+            $uri = OpentalentEnvService::get($public ? 'PUBLIC_API_BASE_URI' : 'API_BASE_URI');
+        }
+
         return rtrim($uri, '/') . '/' . ltrim($trailing_part, '/');
     }
 

+ 2 - 0
ot_core/ext_localconf.php

@@ -37,6 +37,8 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][TYPO3\CMS\Backend\Middleware\Backe
 $GLOBALS['OT'] = array_merge([
     'API_BASE_URI' => 'http://docker.nginx.opentalent.fr',
     'PUBLIC_API_BASE_URI' => 'https://local.api.opentalent.fr',
+    'AP2I_BASE_URI' => 'http://docker.nginx-new.opentalent.fr',
+    'PUBLIC_AP2I_BASE_URI' => 'https://local.ap2i.opentalent.fr',
     'DB_HOST' => 'db',
     'DB_USER' => 'dbcloner',
     'DB_PASSWORD' => 'wWZ4hYcrmHLW2mUK',

+ 89 - 0
ot_templating/Classes/ViewHelpers/HelloAsso/GetFormUrlByEventIdViewHelper.php

@@ -0,0 +1,89 @@
+<?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);
+    }
+}

+ 9 - 0
ot_templating/Resources/Private/Language/locallang.xlf

@@ -427,6 +427,15 @@
 			<trans-unit id="share-bar-description">
 				<source>Boutons de partage de la page vers les réseaux sociaux</source>
 			</trans-unit>
+			<trans-unit id="helloasso-form">
+				<source>Billetterie HelloAsso</source>
+			</trans-unit>
+			<trans-unit id="helloasso-form-description">
+				<source>Formulaire de billetterie HelloAsso</source>
+			</trans-unit>
+			<trans-unit id="event-id">
+				<source>Identifiant de l'évènement Opentalent</source>
+			</trans-unit>
 
 			<!-- Email template -->
 			<trans-unit id="hello">

+ 14 - 0
ot_templating/Resources/Private/Partials/Classic/HelloAssoForm.html

@@ -0,0 +1,14 @@
+<f:comment><!--Contient un formulaire de billeterie Helloasso--></f:comment>
+{namespace ot=Opentalent\OtTemplating\ViewHelpers}
+
+<div class="helloasso-form">
+    <ot:helloAsso.getFormUrlByEventId as="form" eventId="{eventId}">
+        <iframe
+                id="haWidget"
+                allowtransparency="true"
+                src="{form.widgetUrl}"
+                style="width: 100%; border: none;"
+                onload="window.addEventListener( 'message', function(e) { const dataHeight = e.data.height; const haWidgetElement = document.getElementById('haWidget'); haWidgetElement.height = dataHeight + 'px'; } )"
+        ></iframe>
+    </ot:helloAsso.getFormUrlByEventId>
+</div>

+ 14 - 0
ot_templating/Resources/Private/Partials/Modern/HelloAssoForm.html

@@ -0,0 +1,14 @@
+<f:comment><!--Contient un formulaire de billeterie Helloasso--></f:comment>
+{namespace ot=Opentalent\OtTemplating\ViewHelpers}
+
+<div class="helloasso-form">
+    <ot:helloAsso.getFormUrlByEventId as="form" eventId="{eventId}">
+        <iframe
+                id="haWidget"
+                allowtransparency="true"
+                src="{form.widgetUrl}"
+                style="width: 100%; border: none;"
+                onload="window.addEventListener( 'message', function(e) { const dataHeight = e.data.height; const haWidgetElement = document.getElementById('haWidget'); haWidgetElement.height = dataHeight + 'px'; } )"
+        ></iframe>
+    </ot:helloAsso.getFormUrlByEventId>
+</div>

+ 31 - 0
ot_templating/Resources/Private/Templates/Content/HelloAssoForm.html

@@ -0,0 +1,31 @@
+{namespace v=FluidTYPO3\Vhs\ViewHelpers}
+{namespace flux=FluidTYPO3\Flux\ViewHelpers}
+{namespace ot=Opentalent\OtTemplating\ViewHelpers}
+
+<f:comment><!-- Widget flux: : Share Bar --></f:comment>
+
+<f:layout name="{ot:template.current()}/CustomContent" />
+
+<f:section name="Configuration">
+  <flux:form id="HelloAssoForm"
+             label="LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:helloasso-form"
+             description="LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:helloasso-form-description"
+             extensionName="OtTemplating"
+  >
+    <flux:form.option.group value="ot_widgets" />
+    <flux:form.option.icon value="opentalent-icon-144" />
+
+    <flux:field.input name="eventId"
+                    label="LLL:EXT:ot_templating/Resources/Private/Language/locallang.xlf:event-id"
+                    required="1"
+                    eval="int,required" />
+  </flux:form>
+</f:section>
+
+<f:section name="Preview">
+  <p>{f:translate(key: 'helloasso-form-description')}</p>
+</f:section>
+
+<f:section name="Main">
+  <f:render partial="{ot:template.current()}/HelloAssoForm" arguments="{eventId: eventId}" />
+</f:section>