What is the standard way to get/set datetime from fluid in typo3 flow?

2.5k views Asked by At

What is the standard way to get/set datetimes to/from fluid in typo3 flow?

Is there editable html field which - like a basic f:form.textfield - will allow the datetime to be entered, edited and persisted?

I know I can display a datetime with eg <f:format.date format="d.m.Y - H:i:s">{productArticle.classdate}</f:format.date> but in that case the value is null nothing gets displayed and no entry is possible anyway. Does property work with f:format.date in some version? I get "property not registered" when I try it.

Or do I need to have two fields on my page, one for date and one for time, that I put together in the Action?

Thanks

1

There are 1 answers

2
k.tarkin On BEST ANSWER

I'm not sure if it's standard way, and personally I don't like it.. but it can be done like this:

In Fluid for new/edit actions:

<f:form action="create" objectName="girlfriend">
...
<f:form.textfield property="birthDate" placeholder="1991-12-30 - 18:25:58" value="{newGirlfriend.birthDate->f:format.date(format:'Y-m-d - H:i:s')}" />
...
</f:form>

In your controller you can add initialize*Action and update propertyMappingConfiguration for \DateTime if standard isn't good for you (it has to be done for both create and update action):

public function initializeCreateAction() {
    $mappingConfig = $this->arguments['girlfriend']->getPropertyMappingConfiguration();
    $mappingConfig->forProperty('birthDate')->setTypeConverterOption(
        'TYPO3\Flow\Property\TypeConverter\DateTimeConverter',
        \TYPO3\Flow\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,
        'Y-m-d - H:i:s'
    );
}

Sometimes it's easier to not pass object directly to controller but create it on service layer. You can also take a look at TypeConverters - they do not require initializeActions and you can easily override existing ones setting higher priority..