Within the TimestampAgoFormatter class the settingsForm has incorrect variable names for the future_format and past_format fields.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JaceRider created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, 0001-Fix-incorrect-variable-name.patch, failed testing.

himanshu-dixit’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 0001-Fix-incorrect-variable-name.patch, failed testing.

xSDx’s picture

Status: Needs work » Needs review
FileSize
3.62 KB

Pushing patch for future and past format for time ago formatter also rewriting summary, replacing deprecated functions in formating timestamp. this also should solve https://www.drupal.org/node/2427195

xSDx’s picture

Version: 8.2.7 » 8.3.x-dev
mpdonadio’s picture

Component: field system » datetime.module
Status: Needs review » Needs work

Thanks. We really need to scope this to just fix the bug, and not other things, too. So, let's just fix the settings form here.

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php
@@ -174,7 +177,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
-   * @return array
+   * @return FormattableMarkup
    *   The formatted timestamp string using the past or future format setting.
    */
   protected function formatTimestamp($timestamp) {
@@ -186,18 +189,14 @@ protected function formatTimestamp($timestamp) {

@@ -186,18 +189,14 @@ protected function formatTimestamp($timestamp) {
 
     if ($this->request->server->get('REQUEST_TIME') > $timestamp) {
       $result = $this->dateFormatter->formatTimeDiffSince($timestamp, $options);
-      $build = [
-        '#markup' => SafeMarkup::format($this->getSetting('past_format'), ['@interval' => $result->getString()]),
-      ];
+      $setting = $this->getSetting('past_format');
     }
     else {
       $result = $this->dateFormatter->formatTimeDiffUntil($timestamp, $options);
-      $build = [
-        '#markup' => SafeMarkup::format($this->getSetting('future_format'), ['@interval' => $result->getString()]),
-      ];
+      $setting = $this->getSetting('future_format');
     }
-    CacheableMetadata::createFromObject($result)->applyTo($build);
-    return $build;
+
+    return new FormattableMarkup($setting, ['@interval' => $result->getString()]);
   }

This is out of scope, but this is not a correct change. This needs to return a render array fragment to propagate the cache data from the date formatter.

xSDx’s picture

@mpdonadio

Pushing patch just for settings form.
Summary will then be fixed in https://www.drupal.org/node/2686409

xSDx’s picture

Status: Needs work » Needs review

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php
@@ -106,14 +106,14 @@ public static function defaultSettings() {
-    $form['future_format'] = [
+    $elements['future_format'] = [

The fact that this big of a change doesn't trigger any sort of test failure indicates a pretty big lack of test coverage for this formatter, so marking as 'needs tests'.

claudiu.cristea’s picture

mpdonadio’s picture