Add proper nullable support for date form field
authorMatthias Schmidt <gravatronics@live.com>
Sun, 24 Feb 2019 13:29:43 +0000 (14:29 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 24 Feb 2019 13:29:43 +0000 (14:29 +0100)
See #2509

wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php

index 9f26c3a08d7b160310b023b8d75dddc32cca5a99..d2114db3bb802375bd876c0d67ae79cf22462938 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\form\builder\field;
 use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\util\DateUtil;
 
 /**
  * Implementation of a form field for to select a FontAwesome icon.
@@ -11,8 +12,9 @@ use wcf\system\form\builder\field\validation\FormFieldValidationError;
  * @package    WoltLabSuite\Core\System\Form\Builder\Field
  * @since      5.2
  */
-class DateFormField extends AbstractFormField implements IImmutableFormField {
+class DateFormField extends AbstractFormField implements IImmutableFormField, INullableFormField {
        use TImmutableFormField;
+       use TNullableFormField;
        
        /**
         * date time format of the save value
@@ -72,7 +74,12 @@ class DateFormField extends AbstractFormField implements IImmutableFormField {
         */
        public function getSaveValue() {
                if ($this->getValue() === null) {
-                       return null;
+                       if ($this->isNullable()) {
+                               return null;
+                       }
+                       else {
+                               return DateUtil::getDateTimeByTimestamp(0)->format($this->getSaveValueFormat());;
+                       }
                }
                
                return $this->getValueDateTimeObject()->format($this->getSaveValueFormat());