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.
Hi,
Please, how do you hide replacement tokens (argument) if empty? In my case:
Under account setting, I create a new field called userpic.
Message text:
!userpic of !foo
Rules:
Set a data value to !userpic (user picture url).
Set a data value to !foo (user name).
If a user has picture, replacement tokens is ok: userpic-url of name.
But If a user doesn't have picture, replacement tokens said !userpic of name.
Is it normal?
Thanks for the awesome module!
Comment | File | Size | Author |
---|---|---|---|
#20 | message-token-clear-1907264-20.patch | 512 bytes | jacob.embree |
| |||
#10 | message.tokenclear-1907264_1.patch | 763 bytes | jbekker |
Comments
Comment #1
jbekker CreditAttribution: jbekker commentedI have the same problem, does anyone have a solution?
It seems to work the way I want to when I hack the GetText function in message/includes/message.message.inc
And add the following code right under
$token_options = message_get_property_values($this, 'data', 'token options');
$token_options[clear] = TRUE;
So my next question is, can I alter "$this, 'data', 'token options'" for specific messages?
Comment #2
jbekker CreditAttribution: jbekker commentedI've found a way to do this without hacking.. I'm not a Drupal PRO, is there a better way to access the message_type-> data ??
Comment #3
kingandy CreditAttribution: kingandy commentedRules was experiencing behaviour like this - see #1559844: Field token is not replaced when fields are blank. Is Message doing a similar manual token replacement process somewhere?
Comment #4
kingandy CreditAttribution: kingandy commentedWait, disregard my comment, it's using token_replace ... :P
Comment #5
kingandy CreditAttribution: kingandy commentedHere's a patch rolled incorporating #2's form_alter code into the form builder - it's based on the version packaged with Commerce-Kickstart (7.x-1.5) so I'm not sure if it'll be valid against 7.x-1.7 ... Also, probably a parent fieldset (similar to $form['data']['purge']) would be a good idea.
Comment #8
kingandy CreditAttribution: kingandy commentedPosting again with "Needs review" to lure in the testbot. (Apologies for the postspam.)
Comment #10
jbekker CreditAttribution: jbekker commentedI couldn't apply last patch against the latest dev, this one adds the checkbox above the Purge settings fieldset.
Comment #11
amitaibuCommitted, thanks.
Comment #13
mhaamann CreditAttribution: mhaamann commentedPatch in #10 does not fix all scenarios. I am sorry that i cannot explain my scenario better.
But i tracked the bug down to this line. It never loaded the token options:
$token_options = !empty($this->data['token options']) ? $this->data['token options'] : array();
The attached patch fixes tokens not being replaced in the function save() in file: message.message.inc
Its just a copy/paste from how you load the token options in getText() function in the same file - And it works!
Comment #15
amitaibuCan you please re-roll, so simpletest can run.
Comment #16
vojvotkinja CreditAttribution: vojvotkinja commented13: message.tokenclear-1907264_2.patch queued for re-testing.
Comment #18
amitaibuPatch needs a re-roll
Comment #20
jacob.embree CreditAttribution: jacob.embree at St. Louis Integration commentedHere is #13 rerolled.
Comment #21
bluegeek9 CreditAttribution: bluegeek9 as a volunteer commented