diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php index 091b57e..54e7a54 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php @@ -72,16 +72,16 @@ public function viewElements(FieldItemListInterface $items) { * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $elements = parent::settingsForm($form, $form_state); + $form = parent::settingsForm($form, $form_state); - $elements['date_format'] = array( + $form['date_format'] = array( '#type' => 'textfield', '#title' => $this->t('Format string'), '#description' => $this->t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://php.net/manual/function.date.php')), '#default_value' => $this->getSetting('date_format'), ); - return $elements; + return $form; } /** @@ -89,9 +89,11 @@ public function settingsForm(array $form, FormStateInterface $form_state) { */ public function settingsSummary() { $summary = parent::settingsSummary(); + $date = new DrupalDateTime(); $this->setTimeZone($date); $summary[] = $this->appendTimezone($date->format($this->getSetting('date_format'))); + return $summary; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php index f07860b..0cb65f8 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php @@ -171,16 +171,17 @@ protected function formatDate($date) { * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $elements = parent::settingsForm($form, $form_state); + $form = parent::settingsForm($form, $form_state); $time = new DrupalDateTime(); $format_types = $this->dateStorage->loadMultiple(); + $options = []; foreach ($format_types as $type => $type_info) { $format = $this->dateFormatter->format($time->format('U'), $type); $options[$type] = $type_info->label() . ' (' . $format . ')'; } - $elements['format_type'] = array( + $form['format_type'] = array( '#type' => 'select', '#title' => t('Date format'), '#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."), @@ -188,7 +189,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) { '#default_value' => $this->getSetting('format_type'), ); - return $elements; + return $form; } /** @@ -196,8 +197,10 @@ public function settingsForm(array $form, FormStateInterface $form_state) { */ public function settingsSummary() { $summary = parent::settingsSummary(); + $date = new DrupalDateTime(); $summary[] = t('Format: @display', array('@display' => $this->appendTimezone($this->formatDate($date)))); + return $summary; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php index bee1454..c8c8714 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php @@ -31,7 +31,9 @@ public static function defaultSettings() { * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $elements['timezone_override'] = array( + $form = parent::settingsForm($form, $form_state); + + $form['timezone_override'] = array( '#type' => 'select', '#title' => $this->t('Timezone override'), '#description' => $this->t('Always use the selected timezone'), @@ -39,21 +41,22 @@ public function settingsForm(array $form, FormStateInterface $form_state) { '#default_value' => $this->getSetting('timezone_override'), ); - $elements['append_timezone'] = array( + $form['append_timezone'] = array( '#type' => 'checkbox', '#title' => $this->t('Append timezone'), '#description' => $this->t('Append the timezone used to render the date'), '#default_value' => $this->getSetting('append_timezone'), ); - return $elements; + return $form; } /** * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); + $summary = parent::settingsSummary(); + $override = $this->getSetting('timezone_override'); if ($override != '') { $replacements = array( @@ -62,6 +65,7 @@ public function settingsSummary() { ); $summary[] = $override != '' ? $this->t('Timezone: @timezone @appended', $replacements) : ''; } + return $summary; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php index 70f2300..b979a97 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php @@ -137,16 +137,9 @@ public function viewElements(FieldItemListInterface $items) { * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { - $elements = parent::settingsForm($form, $form_state); + $form = parent::settingsForm($form, $form_state); - $time = new DrupalDateTime(); - $format_types = $this->dateStorage->loadMultiple(); - foreach ($format_types as $type => $type_info) { - $format = $this->dateFormatter->format($time->format('U'), $type); - $options[$type] = $type_info->label() . ' (' . $format . ')'; - } - - $elements['format_type'] = array( + $form['format_type'] = array( '#type' => 'select', '#title' => $this->t('Date format'), '#options' => array( @@ -161,24 +154,27 @@ public function settingsForm(array $form, FormStateInterface $form_state) { '#default_value' => $this->getSetting('format_type'), ); - $elements['granularity'] = array( + $form['granularity'] = array( '#type' => 'number', '#title' => 'Interval', '#default_value' => $this->getSetting('granularity'), '#description' => $this->t('How many time units should be shown in the \'time ago\' string.'), ); - return $elements; + return $form; } /** * {@inheritdoc} */ public function settingsSummary() { + $summary = parent::settingsSummary(); + $future_date = new DrupalDateTime('1 year 1 month 1 week 1 day 1 hour 1 minute'); $past_date = new DrupalDateTime('-1 year'); $summary[] = t('Future date: !display', array('!display' => $this->formatDate($future_date))); $summary[] = t('Past date: !display', array('!display' => $this->formatDate($past_date))); + return $summary; }