Commit 9125e13f authored by Jonas Götze's avatar Jonas Götze

[WIP][FEATURE] Generate a slug for new records processed by T3oSaveToDatabaseFinisher

parent 9a8ab3bd
......@@ -15,6 +15,7 @@ namespace T3o\T3orgLayout\Domain\Finishers;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -83,6 +84,27 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD
}
$this->process($optionKey);
$slugFieldName = $this->parseOption('slugFieldName');
if ($slugFieldName !== null && $this->options['mode'] === 'insert') {
$fieldConfig = $GLOBALS['TCA'][$this->options['table']]['columns'][$slugFieldName]['config'];
$slugHelper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\DataHandling\SlugHelper::class,
$this->options['table'],
$slugFieldName,
$fieldConfig
);
$recordUid = $this->finisherContext->getFinisherVariableProvider()->get(
$this->shortFinisherIdentifier,
'insertedUids.' . $optionKey,
);
$record = BackendUtility::getRecord($this->options['table'], $recordUid);
$slug = $slugHelper->generate($record, $record['pid']);
$this->databaseConnection->update(
$this->options['table'],
[$slugFieldName => $slug],
['uid' => $recordUid]
);
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment