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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jbekker’s picture

I 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?

jbekker’s picture

I'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 ??

/**
 * Implements hook_default_message_type_form_alter().
 */
function hook_form_message_type_form_alter(&$form, &$form_state) {
  $form['data']['token options']['clear'] = array(
    '#title' => t('Clear empty tokens'),
    '#type' => 'checkbox',
    '#description' => t('When this option is selected, empty tokens will be removed from display'),
    '#default_value' => !empty($form_state['build_info']['args']['0']->data['token options']['clear']) ? $form_state['build_info']['args']['0']->data['token options']['clear'] : FALSE,
  );
}
kingandy’s picture

Rules 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?

kingandy’s picture

Wait, disregard my comment, it's using token_replace ... :P

kingandy’s picture

FileSize
801 bytes

Here'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.

kingandy’s picture

Category: support » feature
Status: Active » Needs review
FileSize
801 bytes

Posting again with "Needs review" to lure in the testbot. (Apologies for the postspam.)

Status: Needs review » Needs work

The last submitted patch, message.tokenclear.patch, failed testing.

jbekker’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Status: Needs work » Needs review
FileSize
763 bytes

I couldn't apply last patch against the latest dev, this one adds the checkbox above the Purge settings fieldset.

amitaibu’s picture

Status: Needs review » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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

mhaamann’s picture

Status: Closed (fixed) » Needs review
FileSize
639 bytes

Patch 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!

Status: Needs review » Needs work

The last submitted patch, message.tokenclear-1907264_2.patch, failed testing.

amitaibu’s picture

Can you please re-roll, so simpletest can run.

vojvotkinja’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: message.tokenclear-1907264_2.patch, failed testing.

amitaibu’s picture

Issue summary: View changes

Patch needs a re-roll

  • amitaibu committed f0983b1 on 8.x-1.x authored by kingandy
    Issue #1907264 by kingandy, jbekker | iS: Allow Hiding replacement...
jacob.embree’s picture

Status: Needs work » Needs review
FileSize
512 bytes

Here is #13 rerolled.

bluegeek9’s picture

Status: Needs review » Closed (outdated)