Hello,
So after digging around the thread and API for a little while, I'm still a bit puzzled at figuring out a "clean" way of theming PrivateMsg. It seems there are no classes for the message listing table (?)
So far I got it to look like gmail (screenshot attached), but I had to modify three lines in the module core.
Here's the basic idea:
#1. Add message body through API (custom module or phptemplate)
function helper123_privatemsg_sql_list_alter(&$fragments, $account) {
$fragments['select'][] = 'pm.body'; // load 'body' into $row in theme_privatemsg_message_row()
}
function helper123_privatemsg_sql_list_sent_alter(&$fragments, $account) {
$fragments['select'][] = 'pm.body'; // load 'body' into $row in theme_privatemsg_message_row()
}
#2. Customize the message listing output (phptemplate)
function phptemplate_privatemsg_message_row($row) {
$themed_row = array();
$unread = '';
if (isset($row['is_new']) && $row['is_new'] ) {
$unread = ' privatemsg-unread';
}
if (isset($row['author']) && $row['author']) {
$authors = _privatemsg_generate_user_array($row['author']);
$themed_row[t('Authors')] = array('data' => '<span class="privatemsg-list-from'. $unread .'">'. _privatemsg_format_participants($authors, 3, TRUE) .'</span>', 'class' => 'Authors');
}
if (array_key_exists('recipient', $row)) {
$themed_row[t('Recipients')] = '';
if (!empty($row['recipient'])) {
$recipients = _privatemsg_generate_user_array($row['recipient']);
$themed_row[t('Recipients')] = array('data' => '<span class="privatemsg-list-to'. $unread .'">'. _privatemsg_format_participants($recipients, 3, TRUE) .'</span>', 'class' => 'Recipients');
}
}
if (array_key_exists('body', $row)) {
$body = ' - <span class="privatemsg-list-body">'. substr($row['body'], 0, 150) .'</span>';
}
$themed_row[t('Subject')] = array('data' => '<span class="privatemsg-list-subject'. $unread .'">'. l($row['subject'], 'messages/view/'. $row['thread_id']) .'</span>'.$body, 'class' => 'Subject');
if ($row['last_updated']) {
//$themed_row[t('Last updated')] = '<span class="privatemsg-list-date'. $unread .'">'. format_date($row['last_updated'], 'small') .'</span>';
$time_ago = time() - $row['last_updated'];
$themed_row[t('Last updated')] = array('data' => '<span class="privatemsg-list-date'. $unread .'">'. format_interval($time_ago,1) .' ago</span>', 'class' => 'Last-updated');
}
//drupal_set_message(var_export($themed_row,true));
//return $themed_row;
return array('data' => $themed_row, 'class' => $unread);
}
#3. Modify module core (I'd like to avoid this somehow)
Since we're converting simple rows into complex rows, we need to read the 'data' in the array.
find this line:
foreach (array_keys($rows[0]) as $index) {
... and replace with this:
foreach (array_keys($rows[0]['data']) as $index) {
Add some table heading classes:
find this line:
$head[$index] = array('data' => $index);
... and replace with this:
$head[$index] = array('data' => $index, 'class' => preg_replace('/[^a-z0-9_-]/i','-',$index));
Question: Is there a better way to add syntax-safe classes here than preg_replace?
Add a table class
find this line:
$content = theme('table', $head, $rows);
... and replace it with this:
$content = theme('table', $head, $rows, array('class' => 'privatemsg-list'));
The message listing table is now fully themeable.
I have a deadline on this particular project, so I didn't have time to look too deeply into alternatives, but I'd love to hear some ideas about improvements on this and on how to avoid modifying the module core to achieve the same.
Best,
Andrey.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | images.zip | 2.12 KB | mr.andrey |
| privatemsg-gmail.jpg | 99.01 KB | mr.andrey |
Comments
Comment #1
berdirThis looks great!
I'm sure we can find a way to allow this without making changes to the core, I am working on restructuring the list display, which should already eliminate some of your problems. I'll explain it later in #348907: Per thread/Multiple thread actions in detail.
A very short feedback, will come back on you later when the mentioned issue above is working.
#1: This might not work on more strict sql servers like postgresql, I need to check that..
#2: I changed from a simple string to an array just a few hours ago. I did more or less the same as you and added the unread class to the tr tag and moved the span classes to td. I'll explain it in detail later.
#3: I'll add default css classes to the table and the headers...
Would it be possible for you to share your theme modifications so that we could include it as a selectable theme?
Comment #2
mr.andrey commentedGreat. Looking forward to hearing about your progress.
Sure, here is the CSS and images are attached:
I assume you don't need the custom tabs, but if you do, here's the thread with template and all:
#372958: Solution for tabs/QuickTabs that works in IE6, IE7, Firefox 3 and Safari 3 identically
Best,
Andrey.
Comment #3
mr.andrey commentedFor some reason the file didn't attach. Trying again.
Comment #4
mr.andrey commentedHere's a more IE6&7-friendly version (apparently IE needs a div for the gmail-style body overflow to work correctly without breaking lines):
Comment #5
sansui commentedLooks great, but I'm unable to find the lines to change in the current dev code. Perhaps the module has changed significantly since this posting
Comment #6
litwol commented*alot* have changed.
Comment #7
berdirIf we want this in privatemsg, we need some sort of styles support, similiar to advanced forum or panels. advanced forum styles are explained at http://drupal.org/node/512116.
Note that this is definitly post 1.0 but of course, if someone is interested to implement this, feel free to do so.
Comment #8
berdirSetting the correct category, this is a new feature, not a support request.
Comment #9
Bilmar commentedsubscribing - I am very interested in being able to have full control over privatemsg as discussed in this thread.
Comment #10
berdirYou already have, see http://blog.worldempire.ch/de/api/group/theming/1 for more information.
This issue is just about providing different themes with privatemsg.module and the ability to choose between them in the admin UI.
Comment #11
Bilmar commentedmy apologies Berdir -
I am trying to change 'Participants' to 'From' and use field_firstname from content profile, and customize the 'Write new message' page but read about problems with page-messages-new.tpl.php
I will study the link you provided above
Thanks
Comment #12
berdirPrivatemsg should always use theme_username(). However, you might not always have full user objects, especially when displaying a thread (for performance reasons). You can either use user_load() to load the full user or extend the participants query so that it does directly load and return that field (a bit more complicated but better performance). See:
- http://blog.worldempire.ch/api/group/sql/1
- http://blog.worldempire.ch/api/function/privatemsg_sql_participants/1
On the view page? That is a bit tricky because that comes from a function, not a theme: http://blog.worldempire.ch/api/function/_privatemsg_format_participants/1. However, since it's a translated string, you can use string overrides to do that: http://drupal.org/project/stringoverrides
That is a completely different thing, that would be a template suggestion for the *whole* page at messages/new. But you can't use that to change parts of the page.
Comment #13
Bilmar commentedThank you - I was able to successfully change 'Participants' to 'From' using stringoverrides!
I'm currently using email registration module so the username field is hidden at registration and auto set to everything before the @example.com
Therefore, I would like to use field_firstname from cck/content profile (username isn't a variable I have been using on the website)
I have used the below code in .tpl.php files before. Is there something similar I can use to have the 'Participants' column show this field instead of username for each message thread?
Your help is much appreciated!
Comment #14
berdirYou should be able to create a theme_username function (http://api.drupal.org/api/function/theme_username/6) for your theme and it should use that everywhere.
Comment #15
robby.smith commentedthis seems very cool. with privatemsg 6.x-1.1 released, is there any update on this new feature?
Comment #16
faruq1256 commentedI am new to Drupal Please provide How can we change the privatemsg theme list like Gmail in Drupal5.20.I am trying from last 2 days.Please provide some links or Code.
Thank you in Advance.
Comment #17
naheemsays commentedThe drupal 5 version of privatemsg is more or less unsupported. and Drupal 5 itself will probably become unsupported within a couple or three months.
your best bet is to migrate to Drupal 6 (or plan for drupal 7) especially if you are doing new development, which the new theming of messages suggests.
Comment #18
faruq1256 commentedThanking you for reply. But my project almost done.Its a tedious task now for me to migrate in to D6.If possible please provide CSS to change theme. Atleast i can show some what change. Anyways finally what i need is to slightly alter the message list with css
Comment #19
WaQuEe commentedI posted the issue in the wrong place....I appologise
Comment #20
berdirChanging issue settings back to old values...
Comment #21
YK85 commentedsubscribing
Comment #22
fugazi commentedsubscribing
Comment #23
okday commentedsubscribe
Comment #24
dalad commentedsubscribing
Comment #25
Relia commentedHello i read the thread but i don't know where i have to write the code.
the first part in a custom module.
the second part: (#2. Customize the message listing output (phptemplate)) phptemplate what file exactly if is possible someone specifies the name of the file to change.
the third part in the module core, but what module core? In the core folder there are a lot modules.
the css I suppose in the privatemsg.css
Can someone help me???
Comment #26
berdirYou can't apply the existing, Privatemsg has changed a lot since this was proposed. This requires a rather big re-roll.
Comment #27
Witch commentedsubscribe
Comment #28
mrgoltra commentedsubsribing.
Comment #29
achikas commentedsubscribe
Comment #30
jrivelli commentedSo at this time there are no templates for privatemsg? It would be so sweet if there was at least another option besides the default view, Similar to gmail would be nice because it is widely used :)
Comment #31
wickedwookie commentedsubscribe.. seems sensible that there should be some way to adapt the appearance
Comment #32
bkrall commentedThis is awesome. Have you considered releasing this as a submodule to PrivateMsg?
Comment #33
ptmkenny commentedThis issue started off about 5.x version of Privatemsg, so the code examples are old and inaccurate. I'm closing this issue so that it doesn't lead people in the wrong direction. Feel free to start any questions about theming the 7.x version of Privatemsg as new issues.