Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
You can do that in two steps, but you need some php code/knowledge.
1. Either call drupal_get_form('privatemsg_list', 'unread') (which will return the whole page from /messages) or "global $user; $query = _privatemsg_assemble_query('list', $user, 'unread');" (which will just create the necessary query for you in $query['query'] that you then need to use and build your list/page yourself. See #492822: to display latest 5 (more or less) messages for more information about that. See also http://blog.worldempire.ch/api/function/privatemsg_filter_menu/1 for an example to create a menu entry for the first example.
2. Define what the unread query type means by creating the following hook:
function yourmodule_privatemsg_sql_list_alter(&$fragments, $account, $argument) {
if ($argument == 'unread') {
// Only show thread that have atleast one new message.
$fragments['having'][] = 'SUM(pmi.is_new) > 1';
}
}
If you have generic php questions that are not specific to privatemsg.module, please ask them in the forums or irc.
You don't need the second function. Just use 'drupal_get_form' as 'page callback' and then array('privatemsg_list', 'unread') as 'page arguments'.
>
function dealbacker_custom_privatemsg_privatemsg_sql_list_alter(&$fragments, $account, $argument) {
You probably have another module called dealbacker_custom so that hook works but it won't if someone else doesn't have that. also, it is a bit confusing :)
Comments
Comment #1
berdirYou can do that in two steps, but you need some php code/knowledge.
1. Either call drupal_get_form('privatemsg_list', 'unread') (which will return the whole page from /messages) or "global $user; $query = _privatemsg_assemble_query('list', $user, 'unread');" (which will just create the necessary query for you in $query['query'] that you then need to use and build your list/page yourself. See #492822: to display latest 5 (more or less) messages for more information about that. See also http://blog.worldempire.ch/api/function/privatemsg_filter_menu/1 for an example to create a menu entry for the first example.
2. Define what the unread query type means by creating the following hook:
If you have generic php questions that are not specific to privatemsg.module, please ask them in the forums or irc.
Comment #2
achilles085 commentedThank you Berdir!
I followed your suggestion to use drupal_get_form()
for it was easier for me to follow.
what i did is i created a module
first, create a .info file named it as privatemsg_unread.info
Next, Create the module file,named it as privatemsg_unread.module
Put it inside a folder privatemsg_unread upload to your modules folder(usually sites/all/modules)
enable the module(admin/build/module) then voila!!!
To test(if only you have recent unread messages, otherwise no messages will be displayed) ,
try to access www.YOURSITE.com/messages/unread
Feel free to add some more..
Comment #3
berdirGreat, a few comments about your code.
You don't need the second function. Just use 'drupal_get_form' as 'page callback' and then array('privatemsg_list', 'unread') as 'page arguments'.
You probably have another module called dealbacker_custom so that hook works but it won't if someone else doesn't have that. also, it is a bit confusing :)
Comment #4
achilles085 commentedsorry for that...i already updated it.
Another question if you don't mind
If i use this kind of hook menu...what path/file should i call?
I really like the idea of using api's to alter sql queries same as using hook_views_query_alter
thanks again man! you save me a alot of work! :)