Skip to content
Snippets Groups Projects

Issue #3391497: Time-related fields do not show their default values

Merged tyler36 requested to merge issue/examples-3391497:3391497-time-related-field-not into 4.0.x
@@ -2,6 +2,7 @@
namespace Drupal\form_api_example\Form;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
@@ -70,10 +71,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
];
// Date.
$now = new DrupalDateTime();
$form['expiration'] = [
'#type' => 'date',
'#title' => $this->t('Content expiration'),
'#default_value' => ['year' => 2020, 'month' => 2, 'day' => 15],
'#default_value' => $now->format('Y-m-d'),
'#description' => 'Date, #type = date',
];
@@ -82,8 +84,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'datetime',
'#title' => 'Date Time',
'#date_increment' => 1,
'#date_timezone' => date_default_timezone_get(),
'#default_value' => date_default_timezone_get(),
'#default_value' => $now,
'#description' => $this->t('Date time, #type = datetime'),
];
Loading