Currently none of the node tokens in a widget template are expanded when rendered as part of a widget set in a block view because the data parameter of token_replace is not set in hook_block_view and corresponding theme functions. I'm attaching a simple fix which adds the "#token_data" parameter to the widgets_set_view theme function and adds the node object to the data array if the block is being viewed on a node page. This allows all node tokens (e.g. [node:nid], [node:url] etc.) to be used in widgets intended to be displayed in blocks on node pages.

This patch seems to be working for me on 7.x-1.0-beta5, though I haven't tested it on dev.

CommentFileSizeAuthor
block_node_token_support.patch1.01 KBM. George Hansen

Comments

grahamshepherd’s picture

I have the same problem but the proposed patch doesn't work for me.
I have created a widget definition to share to Yammer which looks like this:

<a href="https://www.yammer.com/messages/new?status=[node:url]"><img src="http://mysite.com/sites/all/libraries/social_media/images/yamit20.png" title="Share with Yammer" />
</a>

I have plugged it into a share block but the resulting link is just:

https://www.yammer.com/messages/new?status=[node:url]

Yammer literally takes "[node:url]" but not my node url.

grahamshepherd’s picture

Well. Something strange here. The patch works intermittently. Clear the caches and it doesn't work. Allow the caches to fill and it does.
I'm a dummy. What's going on?