It might be really cool to add a token for the current object on the page that would use menu_get_object(). That way you could reference the current node on the same page, etc. Something like [current-page:object:node:...].

CommentFileSizeAuthor
#16 token-current_page_object_token-919760-16.patch2.33 KBrudiedirkx
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View
#9 token-current_page_object_token-919760-9.patch2.3 KBJohnny vd Laar
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View
#8 token-current_page_object_token-919760-8.patch2.28 KBrudiedirkx
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View
#5 token-current_page_object_token-919760-5.patch2.25 KBrudiedirkx
FAILED: [[SimpleTest]]: [MySQL] 343 pass(es), 4 fail(s), and 0 exception(s). View
#1 token.919760.1.patch1.78 KBjamsilver
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch token.919760.1.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots. View
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

jamsilver’s picture

Status: Active » Needs review
FileSize
1.78 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch token.919760.1.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots. View

Here's a patch which opens up the way for the current page node - but is not generalized to any object.
This patch combines with entity_token, allowing any field / property of the current page node to be accessed.

Status: Needs review » Needs work

The last submitted patch, token.919760.1.patch, failed testing.

Alan D.’s picture

Hi Dave

Any interest or ETA for this? With Webform 7.x-4.x, there is normal token support built-in and this would provide a very nice bridge to provide context between the current page and the webform module.

In saying that, it would be nicer to provide current-[entity name here] like "current-node:nid" rather than "current-page:node:nid". If "current-page:node" pattern is used, maybe the title makes more sense for the default token?

Final point, if this pattern is extended out to multiple entity types, it is going to load up the already heavy token tree a bit, so maybe it is worth making these tokens configurable, even if just a variable_get() with no UI.

Cheers
Alan

greenwe’s picture

This would benefit me as well. Thank you

rudiedirkx’s picture

Status: Needs work » Needs review
FileSize
2.25 KB
FAILED: [[SimpleTest]]: [MySQL] 343 pass(es), 4 fail(s), and 0 exception(s). View

I need this too, so here it is.

I've approached it slightly differently, because Token needs a type for it to be any kind of useful. You could make generic entity tokens like object:id, object:type, object:label, but not much else. All others require a token type.

My patch adds one token per entity type to current-page: current-page:node, current-page:taxonomy_term etc. (I've not changed "taxonomy_term" to "term" on purpose, because in this case it's the name of the entity type, which should be literal (like the taxonomy token types should have been too)).

current-page:node:nid will return the nid.
current-page:node and current-page:node:title will return the node title.

It's rolled against dev (72f3d17).

I'm not really satisfied with the switch { default } token_tokens(), but I was trying to reuse as much Token logic as possible, while still being somewhat performant, so there it is. This is the limit of my Token skills.

rudiedirkx’s picture

And I actually can't seem to load them into my token tree... I tried #token_types => array('current-page') but there's no current-page in the resulting tree.

Status: Needs review » Needs work

The last submitted patch, token-current_page_object_token-919760-5.patch, failed testing.

rudiedirkx’s picture

Status: Needs work » Needs review
FileSize
2.28 KB
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View

Oh wow stupid n00b bug!

Fixed.

Johnny vd Laar’s picture

FileSize
2.3 KB
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View

I think there is an access check missing. When you don't have access to the menu item then there is no $item['map'].

rudiedirkx’s picture

Issue summary: View changes
quicksketch’s picture

I realized I've never commented on this issue, so I wanted to say this would be a huge benefit to Webform users. A *very* common request is being able to make a Webform into a block that is displayed on certain node types. Then users want to prepopulate Webform fields with values from the node on which the block is displayed. This is super-helpful for doing things like feedback forms, contacting the author of the node, recording relevant information, prepopulating node titles in textfields, etc.

How common is this request? Probably a few people every month. Since these requests always end up in the Webform, I thought I'd list the relevant issues to emphasize the commonality of this problem.

#2149463: Setting hidden field to [node:field_email] or [current-page:field_email] - neither work
#2163791: How to use Webform as a replacement for User Contact form: Tokens for User Email?
#1589100: Get the node title into a webform block and change the destination mail address for each node. Is this the right way?
#1620652: I want to create form on each content type "Event"
#1692026: [current-page:url:args] returns "node, 25"
#2061503: Using node field data in emails using tokens?
#2199435: Webform Mail
#2087177: Webform: [node:title] or [current-page:title] tokens display title of webform instead of current page
#1224130: %title token in Webform
#2129199: Node tokes
#2058065: Node Reference form filled in Form
#2213857: Node Tokens from Node into Webform Fields
#1617086: Webform > E-mails: Add "Content values" (ie: node field) support

Needless to say, I would be thrilled if this functionality would be added as it would help a lot of Webform users, and stop the support requests. ;)

rudiedirkx’s picture

Did #9 do it for you?

JayShoe’s picture

quicksketch,

You are right. This is a pretty common requirement and would be an amazing addition to webform. I'll be paying attention to this post to see what happens. Fingers crossed.

In the meantime, for other users searching for this functionality - You can still do it in code. Here is a snippet that worked for me.

<?php

function webform_insert_default_form_alter(&$form, &$form_state, $form_id) {
// you'll want to limit your altering to specific forms
 if ($form_id == 'webform_client_form_2151') {
    // load the current node into $node2
    if ($node2 = menu_get_object()) {
                // populate the venue_email field of the form with field_email of the node. 
		$form['submitted']['venue_email']['#default_value'] = $node2->field_email['und'][0]['email'];
	}
 }	
}

Jay

pingwin4eg’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #9 works. Tested with nodes ([current-page:node:...]) in custom block's body (using token_filter module).

knalstaaf’s picture

I'm using it with Webform, which has on its own a Webform block. This webform block uses a token (of an Entity Reference field) from the node it's being displayed in, and works perfectly on these nodes themselves.

This Webform block also appears on the homepage, which is not a node, nor does it have the token that goes as a default value in the hidden field (contrary to the node described above). As a result I'm getting these errors, only on the homepage:

Warning: array_search() expects parameter 2 to be array, string given in token_tokens() (line 700 of /sites/all/modules/token/token.tokens.inc).
Notice: Undefined index: in token_tokens() (line 703 of /sites/all/modules/token/token.tokens.inc).

The token itself looks like this: [current-page:node:field-sector]

Clearing the Drupal cache does not help.

rudiedirkx’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.33 KB
PASSED: [[SimpleTest]]: [MySQL] 347 pass(es). View

Yes, bug, sometimes load_functions is a string. Weird.

Try this one.

knalstaaf’s picture

#16 gets rid of the errors, thanks!

One more thing is that the ampersands (and probably other special characters, like in French) are displayed as html-code (&amp;) in the results pages of webform (screen). Not sure if this is something that should be addressed in #1665818: Ampersands and other characters are not displayed correctly in <select> widgets instead (applied patch #69, no result).

rudiedirkx’s picture

HTML encoding where it shouldn't is another issue. This issue only adds the objects, not the properties or replacements.

ret5’s picture

#16 Worked well for me!

rudiedirkx’s picture

Status: Needs review » Reviewed & tested by the community
jasom’s picture

#16 worked for me. May you please commit this patch to the latest token release?

scareyclott’s picture

#17 Worked for me too. Please commit patch to latest token release

VISIOS’s picture

#16 works for me too. Thanks to all contributors. :)

hexagoncircle’s picture

Also confirming that #16 is working. Thanks for the patch!

Germanix’s picture

Works for me too. Thanks to all contributors !! :)

mvillares’s picture

Not working, [current-page:node:author:mail] doesn´t working.

jasom’s picture

@mvillares I disagree, you did something wrong. I have just checked if there was any update which broke the functionality. No, there was none. Everything works as it should (mails are generated and delivered).

mvillares’s picture

Oops my mistake! User role problem. Thanks!!!

marcoka’s picture

[current-page:node:author:mail] works if you display the form on the user page like /user/2
confirmed. works. love it. thank you.

caw67’s picture

patch works!

marcoka’s picture

ok i teste that with another site and i updated the system first. now [current-page:node:author:mail] doesnt work when shwoing the form on the /user/2 page.

[current-page:title] works. not sure what happened.

@mvillares what was your role problem?

Alan D.’s picture

ok i teste that with another site and i updated the system first. now [current-page:node:author:mail] doesnt work when shwoing the form on the /user/2 page.

On a user page, (user/%) there will be no context to a content item (node/%) so [current-page:node:author:mail] is a valid token, but current-page:node is undefined, so you will not get anything shown. If it did, technically you have found a bug :)

Try on a node/NID page and it should work.

Without looking up the token tree [current-page:user:mail] is probably what you are after, the email address of the user being displayed.

[edit]
PS: The forums are probably a better place for help rather than issue threads too.

marcoka’s picture

Yes of course you are right, my bad. My brain thought i used [current-page:user:mail] my hand clicked [current-page:node:author:mail] and my eyes saw [current-page:user:mail] :)

I wasnt looking for like "how to support stuff". I was testing the patch, and it works. I hope they will commit it. Thank you for you work.

Alan D.’s picture

Excellent, and sorry for some reason I assumed this was committed already :)

MiloshL’s picture

Hello,

I've patched my token module, but now when i got my rule for example and "send email to address" i can't find [current-page:node:author:mail] in the list. Any suggestions?

Thanks!

jasom’s picture

MiloshL’s picture

@jasom

can you fix images on your site? Also your solution worked! Thanks

AgentJay’s picture

#16 works great for me. It's using the syntax: [current-page:node:field_name]

Needs to be committed. Awesome work!

GiorgosK’s picture

#16 works great, should be committed

jimmynash’s picture

Chiming in. #16 worked perfectly for me to get a current page token into a hidden secure webform component value.

Thanks!

JayShoe’s picture

I just tested this and it works for me too.

Please commit this old issue!

mairoulhs’s picture

#16 worked for me too! I agree, should be committed.

rwilson0429’s picture

Patch at #16 works great and is a huge benefit to the token module users.

Summit’s picture

Hi,
Please commit the patch #16!
Greetings, Martijn

Maurice M.’s picture

#16 worked! Thanks alot! Please include this in the next version.

Bijanzand’s picture

When i enable WEBORM AJAX module, emails will not send !!
Do you have any suggestions ?!

Bijanzand’s picture

When i use WEBORM AJAX module, emails will not send !!
Do you have any suggestions ?!?????

JayShoe’s picture

Bijanzand, don't hijack this thread. Please create a new thread.

kylebehse’s picture

#16 worked first try. Thanks so much!

redsky’s picture

I'd love to see this committed. It would work well for a bunch of our use cases.

cmseasy’s picture

#16 works perfect, please commit.

berenddeboer’s picture

Please commit, great patch.

Vincent_Jo’s picture

#16 essential for following use case: (for those who are looking for solutions)

Webform (as block) - assigned to content-type ( + email-field)
Add email-field from content type as token to the recipient-field (E-mail to address) in the webform:
In my case:
[current-page:node:field_e_mail]

I can then add the form block to the NID-page (panels in my case) and can send mails to the mail address provided by the node of the content-type (to mention that, because I´ve been confused by the term "node" which is used for the available tokens in webforms too: [node:field_e_mail] )

thanks for the patch, please commit

regards

Vincent

alisonjo2786’s picture

+1 would love to have this committed :) Are there any blockers I might be able to help with? Thank you!

[EDIT: Still applies fine against 7.x-1.7, fwiw]

ConradFlashback’s picture

#16 works with 1.7.
Please commit.

JayShoe’s picture

#16 works.
Very old issue. Very useful feature.
Please commit.

dherbold’s picture

#16 saves the day. Please commit already.