We wanted to use a custom display mode for nodes sent via the forward module and discovered that while the view mode worked, they were not being rendered using the tpl.php we'd created for that view mode. It appears that entity_prepare_view / field_attach_view as used in _forward_build_message_content doesn't go through the same render flow that node_view does. The attached patch adds an additional check to the top of _forward_build_message_content to use node_view when we have a node entity, but follow the existing path for all others. This now allows us to use node--forward.tpl.php and have it render as expected into the email body.

CommentFileSizeAuthor
forward-node_view.patch1.03 KBseanr

Comments

john.oltman’s picture

Issue summary: View changes

seanr, just getting to this - do you recall (and I realize this was awhile ago) if you added some code to the theme's template.php file in order to get node--forward.tpl.php recognized as the template? Because I'm not seeing that used otherwise, even after applying your patch.

seanr’s picture

No, we created a view mode called forward, which then made that template suggestion available.

john.oltman’s picture

Except that Drupal 7 doesn't create that suggestion automatically. That's why they had to make that an enhancement in Drupal 8:

https://drupal.org/node/1503464

In D7 you only get node-id and node-content-type suggestions out of the box.

However, I will go ahead and add it for D7 using hook_preprocess_node. I'm pretty sure your project used a preprocess function somewhere, to get that suggestion added.

seanr’s picture

I think the entity module adds it. Not exactly sure as it's been a while. It's definitely not in our template.php and someone else did the majority of the work on the site we needed that for.

john.oltman’s picture

Title: Use node_view if entity_type is node » Add support for entity_view and custom templates
john.oltman’s picture

Status: Needs review » Fixed

I modified the patch to use the more generic entity_view. I also made it optional so existing users aren't affected - to enable entity_view and a theme template, use the new check box "Output themed entity when using custom display" in the DEFAULTS FOR EMAIL THIS PAGE section of Forward admin.

Applied to 7.x-3.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.