Handle non-mandatory DateTime objects
|Priority:||Should have||Due date:|
I yesterday got a problem with one of my models which has two DateTimeProperties which are booth not mandatory. As you may know you can't set a DateTime object to an undefined time, as it's constructed whether with the given time (+format) or without this option with the current local time.
This problem was already discussed in this thread:
The result of this thread was the suggestion to set the properties to string and not DateTime and use a custom validator.
The whole problem seems more to be PHP related than an extbase problem. One solution maybe would be to extend the DateTime class with a custom class which allows to set an undefined time which then results in NULL when any method is called on the object. But this would be a huge affort and maybe a breaking change.
So i looked at the reflection objectaccess and wrote a solution which i hope you will have a look on it. The concept is to use the property refelection to see if the param of the setter method on the object is of type DateTime. If so the value to be set is validated for DateTime. If the value is an instance of DateTime it will be set otherwise it will be obmitted. Before doing this i changed the DateTime converter to not throw an exception if the value couldn't be converted to DateTime it will now return NULL.
Updated by Gerrit Code Review about 1 year ago
- Status changed from New to Under Review
Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/9380