Commit b5a2c1ba authored by Jonas Götze's avatar Jonas Götze
Browse files

[WIP][FEATURE] Add fields for times

parent caa5817f
......@@ -107,4 +107,32 @@ class T3oSaveToDatabaseFinisher extends \TYPO3\CMS\Form\Domain\Finishers\SaveToD
}
}
}
/**
* Prepare data for saving to database
*
* @param array $elementsConfiguration
* @param array $databaseData
* @return array
*/
protected function prepareData(array $elementsConfiguration, array $databaseData)
{
$databaseData = parent::prepareData($elementsConfiguration, $databaseData);
foreach ($this->getFormValues() as $elementIdentifier => $elementValue) {
if ($elementValue instanceof \DateTime) {
$addTimeFromField = $elementsConfiguration[$elementIdentifier]['addTimeFromField'] ?? null;
if ($addTimeFromField !== null && $this->finisherContext->getFormRuntime()->getFormState() !== null) {
[$hours, $minutes] = GeneralUtility::intExplode(
':',
$this->finisherContext->getFormRuntime()->getFormState()->getFormValue($addTimeFromField)
);
$elementValue->setTime($hours, $minutes);
$format = $elementsConfiguration[$elementIdentifier]['dateFormat'] ?? 'U';
$elementValue = $elementValue->format($format);
$databaseData[$elementsConfiguration[$elementIdentifier]['mapOnDatabaseColumn']] = $elementValue;
}
}
}
return $databaseData;
}
}
......@@ -34,8 +34,10 @@ finishers:
mapOnDatabaseColumn: 'title'
startdate:
mapOnDatabaseColumn: 'startdate'
addTimeFromField: 'starttime'
enddate:
mapOnDatabaseColumn: 'enddate'
addTimeFromField: 'endtime'
teaser:
mapOnDatabaseColumn: 'teaser'
description:
......@@ -136,6 +138,22 @@ renderables:
validators:
-
identifier: NotEmpty
-
defaultValue: ''
properties:
fluidAdditionalAttributes:
required: required
elementDescription: 'The time this event starts (hh:mm)'
type: Text
identifier: starttime
label: 'Start time'
validators:
-
identifier: NotEmpty
-
identifier: RegularExpression
options:
regularExpression: '/^(2[0-3]|[01]?[0-9]):([0-5]?[0-9])$/'
-
defaultValue: ''
properties:
......@@ -151,6 +169,22 @@ renderables:
validators:
-
identifier: NotEmpty
-
defaultValue: ''
properties:
fluidAdditionalAttributes:
required: required
elementDescription: 'The time this event ends (hh:mm)'
type: Text
identifier: endtime
label: 'End time'
validators:
-
identifier: NotEmpty
-
identifier: RegularExpression
options:
regularExpression: '/^(2[0-3]|[01]?[0-9]):([0-5]?[0-9])$/'
-
defaultValue: ''
type: Textarea
......
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