Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 13 additions & 27 deletions Classes/Form/Finisher/SaveRepeatableToDatabaseFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,40 +158,26 @@ protected function process(int $iterationCount): void
$this->throwExceptionOnInconsistentConfiguration();

$table = $this->parseOption('table');
$table = is_string($table) ? $table : '';
$elementsConfiguration = $this->parseOption('elements');
$elementsConfiguration = is_array($elementsConfiguration) ? $elementsConfiguration : [];
$databaseColumnMappingsConfiguration = $this->parseOption('databaseColumnMappings');
$repeat = $this->parseOption('repeat');

if (!\is_string($table)) {
throw new FinisherException('Table value is invalid');
}
if (!\is_array($elementsConfiguration)) {
throw new FinisherException('Elements array for table "' . $table . '" is invalid');
}
if (!\is_string($repeat)) {
$repeat = '';
}
$repeat = is_string($repeat) ? $repeat : '';

$this->databaseConnection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);

$databaseData = [];
if (\is_array($databaseColumnMappingsConfiguration)) {
foreach ($databaseColumnMappingsConfiguration as $databaseColumnName => $databaseColumnConfiguration) {
$databaseColumnName = (string) $databaseColumnName;
$value = $this->parseOption('databaseColumnMappings.' . $databaseColumnName . '.value');
if (
empty($value)
&& $databaseColumnConfiguration['skipIfValueIsEmpty'] === true
) {
continue;
}

if (!\is_string($value)) {
throw new FinisherException('Mapping for column "' . $databaseColumnName . '" of table "' . $table . '" is invalid');
}

$databaseData[$databaseColumnName] = $value;
foreach ($databaseColumnMappingsConfiguration as $databaseColumnName => $databaseColumnConfiguration) {
$value = $this->parseOption('databaseColumnMappings.' . $databaseColumnName . '.value');
if (
empty($value)
&& $databaseColumnConfiguration['skipIfValueIsEmpty'] === true
) {
continue;
}

$databaseData[$databaseColumnName] = $value;
}

if ($repeat) {
Expand All @@ -216,7 +202,7 @@ protected function processRepeat($repeat, $elementsConfiguration, $databaseData,
{
$values = $this->getFormValues();
// container does not exist
if (isset($values[$repeat])) {
if (!isset($values[$repeat])) {
$this->throwExceptionOnInconsistentConfiguration();
}
$count = \count($values[$repeat]);
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@
"require-dev": {
"typo3/testing-framework": "^4.14.0",
"extrameile/grumphp-conventions-typo3": "dev-master"
}
},
"extra": {
"typo3/cms": {
"extension-key": "em_form_repeatablesave"
}
}
}