Score:2

How can I change the format used for ?

ng flag

I'm using Drupal 9 to display a RSS feed with the Aggregator module. For the imported items, the date for <pubDate>Wed, 24 Nov 2021 20:05:46 +0000</pubDate> is showed as 2 months 3 weeks ago.

The timestamp fields are already set to use the long format for the date, which is set to M j, Y.

There's no display settings for the Aggregator module. I'm trying to change it with a preprocess hook using the Drupal date formatter, but that doesn't work either.

/**
 * Implements hook_preprocess_aggregator_feed().
 */
function mymodule_preprocess_aggregator_feed(&$variables) {
  $variables['pubDate'] = \Drupal::service('date.formatter')->format($date, 'long');
}

Any help would be greatly appreciated.

apaderno avatar
us flag
A preprocess function name doesn't start with *templateName*; that means that hook is not invoked. It if were invoked, `\Drupal::service('date.formatter')->format($date, 'long')` without initializing `$date` would cause a *PHP Fatal error: Uncaught InvalidArgumentException: The timestamp must be numeric.* error.
Scott B avatar
ng flag
yes i know, i stubbed that in because i dont want my actual template name in this post
Scott B avatar
ng flag
aside from the template name, how would i properly initialize the $date variable for this?
apaderno avatar
us flag
In that case, just use `mymodule_preprocess_aggregator_feed()` as hook name, and users will know that you aren't using the real module name, but replaced it with `mymodule`. You should also show code that works, or describe exactly in that the expected result is different from what you obtain. Saying *it doesn't work* for code that seems incomplete or uses variables without first initializing them doesn't make clear to the users what exactly you don't understand in achieving the described task.
Scott B avatar
ng flag
ok. i changed it to mymodule. Are you able to actually help me figure out how to fix this or not? This is slightly out of my league which is why i posted in the first place
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.