Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hey, I put together a proper integration for Advanced Forum in my theme, and I think it should be simple enough to include this function in the module itself if you like. It could also be controlled by a setting (do you want it themed by advanced forum?) in configuration.
/**
* Theme private messages as advanced forum posts.
*
* @param $vars
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("privatemsg-view" in this case.)
*/
function hook_preprocess_privatemsg_view(&$vars, $hook) {
if (module_exists('advanced_forum')) {
$vars['template_files'][] = 'adv-forum-post';
$vars['top_post'] = FALSE;
// Just use the date for the submitted on.
$vars['submitted'] = format_date($vars['message']['timestamp']);
// Assign the comment to the content variable for consistancy with nodes.
$vars['content'] = $vars['message']['body'];
// User information
$vars['account'] = $vars['message']['author'];
// Create the author pane
$vars['author_pane'] = theme('author_pane', $vars['account'], advanced_forum_path_to_images(), 'privatemsg');
// Create links
$vars['links'] = $vars['message_actions'];
// Title
$vars['title'] = check_plain($vars['message']['subject']);
// Load the signature.
if (variable_get('user_signatures', 0) && $vars['account']->signature) {
$vars['signature'] = check_markup($vars['account']->signature, $vars['account']->signature_format);
}
}
return $vars;
}
It pretty much covers everything that Advanced Forum needs to theme it. As it is, it can be put into a theme, but I imagine it could be integrated directly into privatemsg instead. It only activates if module_exists('advanced_forum');
so it shouldn't add a dependency, just an option.
Comment | File | Size | Author |
---|---|---|---|
#12 | advanced_forum_privatemsg_theme_integration-824480-12.patch | 5.77 KB | mcdruid |
#9 | advf_privatemsg.patch | 6.49 KB | meustrus |
#6 | advf_privatemsg.patch | 6.52 KB | meustrus |
Comments
Comment #1
meustrus CreditAttribution: meustrus commentedOK, so it doesn't actually work. I though I saw results because I had copied the advf-forum-post.tpl.php file as privatemsg-view.tpl.php and some stuff that wasn't implemented before didn't work. I did catch an error in my code where it should say 'advf-forum-post.tpl.php' instead of 'adv-forum-post.tpl.php' but Drupal refuses to use the advf-forum-post template instead of the privatemsg-view template.
Comment #2
meustrus CreditAttribution: meustrus commentedMoving to Advanced Forum, as it has become clear I've been coming at this from the wrong direction. I solved the problem by adding 'privatemsg_view' to
$templates
inadvanced_forum_theme_registry_alter
.With that fix in place, and some additional improvements, here is the revised code:
All that remains from this is some theming considerations. The main problem is that privatemsg does not provide a plain array of message actions, so there is no easy way to change something for the
$links
in the post template. Specifically, they areclass='message_actions'
instead ofclass='links forum-links
. There would either need to be a workaround in the theme (what I've done with my custom skin) or some way of changing the class of the<ul>
.Comment #3
MichelleThis is similar in idea to theming all comments even outside the forum so I can see a place for this. Will have to be in 2.x, though, so needs adapting as well as an option added to settings since not everyone will want this..
Thanks,
Michelle
Comment #4
meustrus CreditAttribution: meustrus commentedWorking with the 2.x version. I see it's gotten a lot more complicated. So far I've added
'privatemsg_view',
to the list inadvanced_forum_theme_registry_alter
, added this into 'includes/theme.inc':And created a new file, 'includes/advanced_forum_preprocess_privatemsg_view.inc':
It mostly works. It doesn't pull any style CSS, though, and I don't know how to put in a setting to turn the preprocess on or off. I left an 'if (TRUE)' in place to gett the variable at a later time.
Comment #5
meustrus CreditAttribution: meustrus commentedCould anybody take a look at this and help me do whatever else is necessary to get CSS in?
Comment #6
meustrus CreditAttribution: meustrus commentedAlright, I figured out the CSS issue, added a setting on the Advanced Forum configuration page, and put some considerable work into porting my changes to the dev-2.x version (it's quite different from alpha3! Maybe it's time for an alpha4?) There needs to be a small change in post.tpl.php in naked to allow for there to be no $node variable when checking if the post is published. While there, I noticed a bug and fixed it: the text is
t("Unpublished Post")
when it should be<?php t("Unpublished Post"); ?>
(in other words, the t() is displayed as HTML instead of being processed as PHP).Behold my patch of fancy fanciness! (I'm so proud of myself for figuring out how to make patches, or rather, for finding the manual page that describes how to do so)
Comment #7
MichelleThanks for doing this. I'm not ignoring you; just have been focused on getting the stuff finished up that I want to get into Alpha 4. I'll have a look at this soon as I can.
Michelle
Comment #8
meustrus CreditAttribution: meustrus commentedIt should be noted that the integration works with privatemsg-6.x-2.x-dev. I remember changing some things when upgrading from privatemsg-6.x-1.3, but it could have been CSS for remaining parts of the page (participants, pager).
Also, there may be some theming considerations that I haven't touched on with the post links; since privatemsg does not provide an array of links, I had to use the existing HTML which has
class='privatemsg-message-links'
instead ofclass='links inline'
.There's also some additional CSS I used in my theme to...tame the participant list and pager:
That I am sure only works for the dev version of privatemsg (the class names/ids are different).
Comment #9
meustrus CreditAttribution: meustrus commentedAlso, there were some small errors in my previous patch related to getting class and ID for the post. I've attached a better patch.
Comment #10
Michsk CreditAttribution: Michsk commentedGreat just what i need.
Comment #11
dreamdust CreditAttribution: dreamdust commentedPatch works great!
Only problem I have noticed is it breaks the #new tag for new/unread private messages.
Comment #12
mcdruidmeustrus, sorry it's taken us a long time to look at this.
Your patch in #9 no longer applies to 6.x-2.x-dev, so I've fixed that and attached the updated patch.
I've noticed at least one problem - the theming of PMs doesn't work well without author_pane, which may not be installed on some sites, as it's not a dependency of the 6.x-2.x branch. Without it the left hand side of the PM is an empty div. This should degrade better in the absence of author_pane.
On a more general note, I wonder if it would be a good idea to wrap the settings checkbox with a check for the presence of the privatemsg module, in order to reduce clutter when the settings's not relevant (you do explain that the setting won't do anything in the description).
I've tested your changes with privatemsg-6.x-1.5 (the current Recommended release) and 6.x-2.x-dev as at 2011-Jun-25. It seemed to work the same with both - I think it's important that the integration code works with the current recommended release, and not just the dev version (as suggested in your comment above, which was probably correct at the time).
If you - or anyone else who wants this functionality - are able to put a bit more work into this, I'll do my best to get it reviewed and committed.
Comment #13
MichelleIs anyone still willing to work on this? Otherwise, let's bump it to D7.