diff --git a/Classes/Transformation/Form/AbstractFormTransformation.php b/Classes/Transformation/Form/AbstractFormTransformation.php index 3f95a49..03e18fa 100644 --- a/Classes/Transformation/Form/AbstractFormTransformation.php +++ b/Classes/Transformation/Form/AbstractFormTransformation.php @@ -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; diff --git a/Documentation/Features/Index.rst b/Documentation/Features/Index.rst index 57b4138..6384ef5 100644 --- a/Documentation/Features/Index.rst +++ b/Documentation/Features/Index.rst @@ -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