3

When an individual private message thread is viewed, it displays the thread messages from oldest to newest, followed by the "Reply" field. I'd like to show the "Reply" field first, and then the thread messages from newest to oldest. How can I reverse the order of the page in this way? I cannot find anything in the code that would point me toward something to re-theme it in a descending order instead of ascending.

Something like this:

[REPLY FIELD]

[Message on Jan 6 2017 at 11:30am]

[Message on Jan 6 2017 at 11:05am]

[Message on Jan 6 2017 at 10:00am]

[Message on Jan 5 2017 at 11:45am]

...instead of the current layout/ordering, which is like this:

[Message on Jan 5 2017 at 11:45am]

[Message on Jan 6 2017 at 10:00am]

[Message on Jan 6 2017 at 11:05am]

[Message on Jan 6 2017 at 11:30am]

[REPLY FIELD]

  • You could hack/modify the privatemsg.module and change lines 1114 and 1117. After, remember to flush the cache to see changes. – No Sssweat Jan 7 '17 at 1:46
  • @NoSssweat, I tried what you suggested, and it does indeed work to re-order the replies so they are descending. Thanks! However, I'd prefer not to hack the Privatemsg module files. I tried adding that function to my template.php file, changing line 1100 to "function my_themename_privatemsg_sql_messages($threads, $account = NULL, $load_all = FALSE) {", but that has no effect (I cleared cache multiple times). Any idea why that won't work? Any other ways I can get it to work, outside of hacking the module? – hockey2112 Jan 7 '17 at 6:50
3

Any other ways I can get it to work, outside of hacking the module?

There is no way to alter a module from another php file / module unless it provides a hook, luckily here they did.

I must be blind, right above it (line 1098), it says in the comments: * @see hook_query_privatemsg_messages_alter()

I found the doc hook_query_privatemsg_messages_alter. Hooks go inside modules, more specifically inside the .module file and you replace the word hook with the actual name of your module.

So create a custom module, inside of mymodule.module (Here we assume your module is called/named mymodule)

/**
 * Implements hook_query_privatemsg_messages_alter().
 */
function mymodule_query_privatemsg_messages_alter($query) {
   $query
     ->orderBy('pm.timestamp', 'DESC')
     ->orderBy('pmi.mid', 'DESC');
}

Side note:

Don't confuse hooks with templates_something_something() those go inside your template.php file. Ex: template_preprocess_node and you replace the word template with the actual name of your theme.


No Sssweat, can I bother you for one other thing? I'd like to move the reply box above the message thread. I found where this is handled in the module (privatemsg.pages.inc, lines 892 and 926). How would I override those two lines (adjusting the "weight" values so that the reply box is a lower weight than the message thread) without hacking the inc file? Would it be done somehow in a custom module?

You're suppose to use hook_privatemsg_view_alter

Sadly, it does not work for reply or message; even though, when I dump dpm($content) using Devel the array it has changed the weight. Works for pager only. Looks like this is a bug.

/**
 * Implements hook_privatemsg_view_alter().
 */
function mymodule_privatemsg_view_alter($content) {

    $content['pager']['#weight'] = -3; // does not work
    $content['reply']['#weight'] = -5; // does not work
    // nor it does not work when doing $content['message']['#weight'] = -5; 

}

If I comment out the $content['pager']['#weight'] = 3 and $content['reply']['#weight'] = -5; from the module, the hook works.

  • 1
    Fantastic, this is absolutely perfect. Thank you so much! I really appreciate your insight into the poor method I was trying to use as well, learn something new every day. :) – hockey2112 Jan 7 '17 at 19:01
  • No Sssweat, can I bother you for one other thing? I'd like to move the reply box above the message thread. I found where this is handled in the module (privatemsg.pages.inc, lines 892 and 926). How would I override those two lines (adjusting the "weight" values so that the reply box is a lower weight than the message thread) without hacking the inc file? Would it be done somehow in a custom module? – hockey2112 Jan 7 '17 at 21:18
  • @hockey2112 I am afraid you will have to hack it, there seems to be a bug. (see updated answer) – No Sssweat Jan 8 '17 at 1:17

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.