Skip to content

Commit

Permalink
Merge pull request #87 from Moongazer/fix/issue-85
Browse files Browse the repository at this point in the history
[FIX] issue #85
  • Loading branch information
ekkeguembel authored Aug 24, 2023
2 parents e81f8af + 21b46b0 commit 8c024c3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
72 changes: 43 additions & 29 deletions Classes/Transformation/Form/AbstractFormTransformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,38 +203,52 @@ protected function updateCustomFields()
if ($formElement['identifier'] === $alias) {
$mauticField = $fieldRepository->getContactFieldByAlias($formElement['properties']['mauticTable']);

if (is_array($mauticField) && isset($mauticField['properties'])) {
$existingProperties = $mauticField['properties']['list'];
$newProperties = [];

foreach ($properties as $propertyKey => $property) {
foreach ($existingProperties as $existingKey => $existingProperty) {
if ($existingProperty['value'] == $property['value']) {
$newProperties[] = [
'label' => $property['label'],
'value' => $property['value'],
];
unset($existingProperties[$existingKey]);
unset($properties[$propertyKey]);
if (isset($mauticField['properties'])) {
// we must distinguish the custom-field types here, and perform required updates only for certain types!
// otherwise errors can appear e.g. accessing non-existing array-keys which has the effect, that
// mauticId and mauticAlias attributes getting lost while saving the form-config (see https://github.com/mautic/mautic-typo3/issues/85)
switch ($mauticField['type']) {
case 'boolean':
// nothing to do here, as we're handling only 0 and 1 values
break;

case 'select':
$existingProperties = $mauticField['properties']['list'];
$newProperties = [];

foreach ($properties as $propertyKey => $property) {
foreach ($existingProperties as $existingKey => $existingProperty) {
if ($existingProperty['value'] == $property['value']) {
$newProperties[] = [
'label' => $property['label'],
'value' => $property['value'],
];
unset($existingProperties[$existingKey]);
unset($properties[$propertyKey]);
}
}
}
}
}

if (!empty($properties)) {
$response = $fieldRepository->editContactField(
$mauticField['id'],
[
'properties' => [
'list' => array_merge($existingProperties, $properties, $newProperties),
],
]
);

if (isset($response['errors']) && is_array($response['errors'])) {
foreach ($response['errors'] as $error) {
$this->logger->critical($error['code'] . ':' . $error['message']);
if (!empty($properties)) {
$response = $fieldRepository->editContactField(
$mauticField['id'],
[
'properties' => [
'list' => array_merge($existingProperties, $properties, $newProperties),
],
]
);

if (isset($response['errors']) && is_array($response['errors'])) {
foreach ($response['errors'] as $error) {
$this->logger->critical($error['code'] . ':' . $error['message']);
}
}
}
}
break;

default:
// todo: probably nothing
}
}
break;
Expand Down
6 changes: 6 additions & 0 deletions Documentation/Features/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ added to the form. The demo form should already have this added.
.. figure:: 009.png
:class: with-shadow

.. warning::
**IMPORTANT:** If you want to have multiple finisher for your form, keep in mind that the order matters! Make sure to add the Mautic
finisher's first, and TYPO3 finisher like "Redirect to a page" or other 3rd party finishers after it! For example, if
by mistake the "Redirect to a page" is placed before the "Send to Mautic Form" finisher, the API call to Mautic never
happens and no data are submitted.

With this set, all data submitted to the form will automatically be saved in Mautic.

Now let's make sure Mautic knows what kind of data is submitted in the form fields. For instance, if you have a field
Expand Down

0 comments on commit 8c024c3

Please sign in to comment.