TCA: Default date/time and range cannot be set dynamically anymore
We have examples in the documentation on how to set dynamic defaults and allowed range for a date field. Here is TYPO3 7.6 for instance (https://docs.typo3.org/m/typo3/reference-tca/7.6/en-us/Reference/Columns/Input/Index.html):
In this example the upper limit is set to the last day in year 2020 while the lowest possible value is set to the date of yesterday:'range' => array( 'upper' => mktime(0, 0, 0, 12, 31, 2020), 'lower' => mktime(0,0,0,date('m'), date('d'), date('Y')) )
This does not work anymore since the TCA is now [since v7] cached. Here is a real-world example:
'start_date' => [ 'exclude' => 0, 'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:tx_myext_domain_model_status.start_date', 'config' => [ 'type' => 'input', 'size' => 11, 'max' => 11, 'eval' => 'date', 'checkbox' => 1, 'default' => mktime(0, 0, 0, date('m'), date('d'), date('Y')), 'range' => [ 'upper' => mktime(23, 59, 59, date('m'), date('d'), date('Y')) + 12 * 7 * 86400, // up to 12 weeks in future ], ], ],
And here is the actual configuration using Backend module System > Configuration > TCA:
As you see, the actual TCA values are those when the system cache was last flushed, and it is not dynamic anymore.
It looks like this problem has been silently forgotten as the documentation starting from TYPO3 v8 (https://docs.typo3.org/m/typo3/reference-tca/8.7/en-us/ColumnsConfig/Type/Input.html) does not show a dynamic value anymore:
In this example the upper limit is set to the last day in year 2020 while the lowest possible value is set to the date of 2014:'range' => [ 'upper' => mktime(0, 0, 0, 12, 31, 2020), 'lower' => mktime(0, 0, 0, 1, 1, 2014), ],
Question: apart from regularly flushing the system cache (this is what I do on much bigger instance because I deploy regularly and explains why I never figured out this problem before!), what is the official way of achieving this behaviour as up to TYPO3 v6?
#1 Updated by Georg Ringer 11 days ago
The best way is something like that: https://github.com/georgringer/news/blob/master/Classes/Backend/FormDataProvider/NewsRowInitializeNew.php
this is also far more powerful as you can just do anything