Connect contact forms with buspro api

This commit is contained in:
Björn Fromme
2019-09-09 13:54:43 +02:00
parent 5827af2b5f
commit d59748a030
14 changed files with 417 additions and 66 deletions
@@ -26,6 +26,7 @@ namespace EP\EpTheme\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use EP\EpTheme\Service\BookingApiService;
use EP\EpTheme\Service\EmailService;
use EP\EpTheme\Domain\Model\Dto\ContactForm;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
@@ -40,12 +41,20 @@ class AjaxFormController extends ActionController
protected $emailService;
/**
* @param EmailService $emailService
* @var BookingApiService
*/
public function __construct(EmailService $emailService)
protected $bookingApiService;
/**
* @param EmailService $emailService
* @param BookingApiService $bookingApiService
*/
public function __construct(EmailService $emailService, BookingApiService $bookingApiService)
{
parent::__construct();
$this->emailService = $emailService;
$this->bookingApiService = $bookingApiService;
}
/**
@@ -63,6 +72,15 @@ class AjaxFormController extends ActionController
[ 'contactForm' => $contactForm ]
);
$addressData = [
'name' => $contactForm->getName(),
'vorname' => $contactForm->getFirstName(),
'email' => $contactForm->getEmail(),
'geschlecht' => $contactForm->getGender(),
];
$this->bookingApiService->registerAddress($addressData);
return json_encode($response);
}
@@ -42,6 +42,18 @@ class ContactForm
*/
protected $name;
/**
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*/
protected $firstName;
/**
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
*/
protected $gender;
/**
* @var string
*/
@@ -121,6 +133,38 @@ class ContactForm
$this->name = $name;
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getGender()
{
return $this->gender;
}
/**
* @param string $gender
*/
public function setGender($gender)
{
$this->gender = $gender;
}
/**
* @return string
*/
@@ -0,0 +1,41 @@
<?php
namespace EP\EpTheme\Form;
use EP\EpTheme\Service\BookingApiService;
use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;
class BpnApiFinisher extends AbstractFinisher
{
/**
* @var BookingApiService
*/
protected $bookingApiService;
/**
* @param BookingApiService $bookingApiService
*/
public function injectBookingApiService(BookingApiService $bookingApiService)
{
$this->bookingApiService = $bookingApiService;
}
/**
* @return string|null
*/
protected function executeInternal()
{
$formValues = $this->finisherContext->getFormValues();
$addressData = [
'name' => $formValues['name'],
'vorname' => $formValues['vorname'],
'geschlecht' => $formValues['geschlecht'],
'email' => $formValues['email'],
'strasse' => $formValues['strasse'],
'plz' => $formValues['plz'],
'ort' => $formValues['ort'],
'telefon' => $formValues['telefon'],
];
$this->bookingApiService->registerAddress($addressData);
}
}
@@ -0,0 +1,56 @@
<?php
namespace EP\EpTheme\Service;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
class BookingApiService implements SingletonInterface
{
/**
* @var string
*/
protected $apiToken;
/**
* @var string
*/
protected $apiEndpointUrl;
/**
* @param ConfigurationManagerInterface $manager
*/
public function __construct(ConfigurationManagerInterface $manager)
{
$settings = GeneralUtility::removeDotsFromTS(
$manager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
);
$this->apiToken = $settings['plugin']['tx_eptheme']['settings']['myEpApiToken'];
$this->apiEndpointUrl = $settings['plugin']['tx_eptheme']['settings']['myEpApiBaseUrl'];
}
/**
* @param array $addressData
*/
public function registerAddress(array $addressData)
{
$client = HttpClient::create();
try {
$client->request('POST', $this->apiEndpointUrl . '/booking/address', [
'headers' => [
'X-AUTH-TOKEN' => $this->apiToken,
],
'body' => [
'data' => $addressData,
],
]);
}
catch (TransportExceptionInterface $e)
{}
}
}
@@ -11,6 +11,9 @@ TYPO3:
prototypes:
standard:
finishersDefinition:
BpnApiFinisher:
implementationClassName: 'EP\EpTheme\Form\BpnApiFinisher'
formElementsDefinition:
Form:
renderingOptions:
@@ -157,7 +157,9 @@ plugin.tx_eptheme {
partnerIdSelectLabel =
# cat=eptheme/900/100; type=string; label=MyE&P API base url
myEpApiBaseUrl = https://myep.burn.dpn
myEpApiBaseUrl =
# cat=eptheme/900/110; type=string; label=MyE&P API auth token
myEpApiToken =
}
}
@@ -88,6 +88,7 @@ plugin.tx_eptheme {
conceptsPageUid = {$plugin.tx_eptheme.settings.conceptsPageUid}
myEpPageUid = {$plugin.tx_eptheme.settings.myEpPageUid}
myEpApiBaseUrl = {$plugin.tx_eptheme.settings.myEpApiBaseUrl}
myEpApiToken = {$plugin.tx_eptheme.settings.myEpApiToken}
facebookViewContentValues {
productUid = {$plugin.tx_eptheme.settings.facebookViewContentProductUid}
nameInternal = {$plugin.tx_eptheme.settings.facebookViewContentNameInternal}
@@ -7,12 +7,16 @@ label: Kontaktformular
prototypeName: contactform
finishers:
-
identifier: BpnApiFinisher
options:
subject: 'Kontaktanfrage von {text-1}'
apiToken: foobarbaz
-
options:
subject: 'Kontaktanfrage von {vorname} {name}'
recipientAddress: [email protected]
recipientName: 'E&P Reisen'
senderAddress: '{text-4}'
senderName: '{text-1}'
senderAddress: '{email}'
senderName: '{vorname} {name}'
replyToAddress: [email protected]
carbonCopyAddress: ''
blindCarbonCopyAddress: ''
@@ -38,11 +42,11 @@ renderables:
-
defaultValue: ''
type: Text
identifier: text-1
label: Name
identifier: vorname
label: Vorname
properties:
fluidAdditionalAttributes:
placeholder: 'Vor- & Nachname'
placeholder: 'Vorname'
required: required
elementDescription: ''
validators:
@@ -51,21 +55,34 @@ renderables:
-
defaultValue: ''
type: Text
identifier: text-2
label: Anschrift
identifier: name
label: Nachname
properties:
fluidAdditionalAttributes:
placeholder: 'Straße & Nr.'
placeholder: 'Nachname'
required: required
elementDescription: ''
validators:
-
identifier: NotEmpty
-
properties:
options:
m: m
w: w
d: d
fluidAdditionalAttributes:
required: required
type: SingleSelect
identifier: geschlecht
label: Gender
validators:
-
identifier: NotEmpty
-
defaultValue: ''
type: Text
identifier: text-3
label: 'PLZ, Ort'
-
defaultValue: ''
type: Text
identifier: text-4
identifier: email
label: E-Mail
properties:
fluidAdditionalAttributes:
@@ -78,16 +95,35 @@ renderables:
-
defaultValue: ''
type: Text
identifier: text-5
identifier: strasse
label: Straße
properties:
fluidAdditionalAttributes:
placeholder: 'Straße & Nr.'
elementDescription: ''
-
defaultValue: ''
type: Text
identifier: plz
label: 'PLZ'
-
defaultValue: ''
type: Text
identifier: ort
label: 'Ort'
-
defaultValue: ''
type: Text
identifier: telefon
label: Telefon
-
defaultValue: ''
type: Textarea
identifier: textarea-1
identifier: message
label: 'Deine Kontaktanfrage'
-
type: Checkbox
identifier: checkbox-1
identifier: privacypolicyaccepted
label: 'Ich habe die Datenschutzbestimmungen gelesen und akzeptiere sie'
properties:
elementDescription: ''
@@ -76,6 +76,9 @@
<trans-unit id="tx_eptheme.message.contactForm.name.1221560718">
<target>Bitte angeben</target>
</trans-unit>
<trans-unit id="tx_eptheme.message.contactForm.firstName.1221560718">
<target>Bitte angeben</target>
</trans-unit>
<trans-unit id="tx_eptheme.message.contactForm.email.1221560718">
<target>Bitte angeben</target>
</trans-unit>
@@ -75,6 +75,9 @@
<trans-unit id="tx_eptheme.message.contactForm.name.1221560718">
<source>Bitte angeben</source>
</trans-unit>
<trans-unit id="tx_eptheme.message.contactForm.firstName.1221560718">
<source>Bitte angeben</source>
</trans-unit>
<trans-unit id="tx_eptheme.message.contactForm.email.1221560718">
<source>Bitte angeben</source>
</trans-unit>
@@ -18,6 +18,18 @@
<div class="help-block"
v-show="formErrors.name" v-html="formErrors.name"></div>
</div>
<div class="form-group" :class="{ 'has-error': formErrors.firstName }">
<label for="firstName" class="control-label">Vorname*</label>
<f:form.textfield class="form-control" property="firstName"/>
<div class="help-block"
v-show="formErrors.firstName" v-html="formErrors.firstName"></div>
</div>
<div class="form-group" :class="{ 'has-error': formErrors.gender }">
<label for="gender" class="control-label">Gender*</label>
<f:form.select class="form-control" property="gender" options="{m: 'M', w: 'W', d: 'D'}"/>
<div class="help-block"
v-show="formErrors.gender" v-html="formErrors.gender"></div>
</div>
<div class="form-group" :class="{ 'has-error': formErrors.company }">
<label for="company" class="control-label">Firma/Verein</label>
<f:form.textfield class="form-control" property="company"/>
@@ -12,12 +12,24 @@
pageUid="{settings.defaultAjaxUid}" class="border"
additionalAttributes="{'v-show': '!success', '@submit.prevent': 'submitForm()'}">
<f:form.hidden property="pageUrl"/>
<div class="form-group" :class="{ 'has-error': formErrors.gender }">
<label for="gender" class="control-label">Geschlecht</label>
<f:form.select options="{m: 'm', w: 'w', d: 'd'}" property="gender" />
<div class="help-block"
v-show="formErrors.gender" v-html="formErrors.gender"></div>
</div>
<div class="form-group" :class="{ 'has-error': formErrors.name }">
<label for="name" class="control-label">Name</label>
<f:form.textfield class="form-control" property="name"/>
<div class="help-block"
v-show="formErrors.name" v-html="formErrors.name"></div>
</div>
<div class="form-group" :class="{ 'has-error': formErrors.firstName }">
<label for="firstName" class="control-label">Vorname</label>
<f:form.textfield class="form-control" property="firstName"/>
<div class="help-block"
v-show="formErrors.firstName" v-html="formErrors.firstName"></div>
</div>
<div class="form-group" :class="{ 'has-error': formErrors.email }">
<label for="email" class="control-label">E-Mail</label>
<f:form.textfield class="form-control" property="email"/>