2

Is there a way to change the date format in main forum table? I changed the date format in views for topic list, but the date format wasn't changed on main forum page

1

What I did to change the date format. In modules/advanced_forum/includes/theme.inc I found the function advanced_forum_preprocess_forum_submitted(&$variables) and changed line 249 to $cutoff = variable_get('advanced_forum_time_ago_cutoff', 0) * 60 * 60; and line 254 - to $variables['date_posted'] = format_date($timestamp, 'custom', 'j M Y, G:i');

1

You generally don't want to edit Core or contributed modules but instead make a module that implements a hook to get your changes to work without effecting your ability to update.

To make this change I created a custom date format via the UI in Drupal 7 at 'admin/config/regional/date-time/formats'

Then I set my module's weight to 1 higher than the advanced forum module's weight in the drupal_system table via direct database manipulation. This allows your module's hook to run after the advanced_forum module's hooks.

I then added a function to a custom module that implements hook_preprocess_HOOK

/**
 * Implements hook_preprocess_HOOK().
 *
 * Changes date format for latest posts on forum listing page "/forums"
 *
 * requires module to be set as higher weight than the advanced_forum module (default 15) in drupal_system
 * this module must be set to weight 16 to make sure the preprocess functions happen after advanced_forum
 */
function forum_enhancements_preprocess_forum_submitted(&$variables) {
  if (isset($variables['topic']->created)) {
    $timestamp = $variables['topic']->created;
    $interval = REQUEST_TIME - $timestamp;
    $variables['time'] = format_interval($interval);

    // For items posted more than $cutoff hours ago, offer an actual date.
    $cutoff = variable_get('advanced_forum_time_ago_cutoff', 48) * 60 * 60;
    if ($interval > $cutoff) {
      $variables['date_posted'] = format_date($timestamp, 'forum');
    }
    else {
      unset($variables['date_posted']);
    }
  }
}
0

You can accomplish this task in multiple ways. The easier is to override forum-list.tpl.php or forum-topic-list.tpl.php and change the date format directly from the template file.

0

In order to change date format for main forum table, you need to override template_preprocess_forum_list by placing it in your Drupal custom theme or Drupal custom module

function MODULE_NAME_OR_THEME_NAME_preprocess_forum_list(&$variables) {
  foreach ($variables['forums'] as $id => $forum) {
    $variables['forums'][$id]->last_reply = format_date($forum->last_post->created); 
  }
}

For more details check Drupal formate_date

0

One thing you should keep in mind while working with Drupal is that you should Never hack Core and its features. You should not be looking at a way to change the date format in table, instead, you should be looking towards a way to manipulate the template where you need to show.

Currently, you should change the way it is shown while rendering in the template file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.