How to flip order of Privatemsg thread from ASC to DESC? When an individual private message thread is viewed, it displays the thread messages from oldest to newest, followed by the &quot;Reply&quot; field. I'd like to show the &quot;Reply&quot; 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]
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
     -&gt;orderBy('pm.timestamp', 'DESC')
     -&gt;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.