This is a follow-up to #1101616: Friendlier tokens:

In one of my views-send-enabled views, I have two tokens for the same replacement: [field_profile_full_name-raw] (from "CCK computed_field tokens") and [views-send-field_profile_full_name]. The first one works properly, but the second one will be replaced by an empty string.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hansfn’s picture

Assigned: Unassigned » hansfn

What formatting have you chosen for the full name field in the view? What type of CCK field is it? Does it happen if you output it unformatted too? (Is it fetched through a relation or directly from the node/user.)

I tried to reproduce it myself, but failed...

roball’s picture

The field is of type "Computed" (provided by the Computed Field module). The Computed Code is

$node_field[0]['value'] = $node->field_profile_first_name[0]['value'] . ' ' . $node->field_profile_last_name[0]['value'];

and the Display Format is

$display = $node_field_item['value'];

field_profile_first_name and field_profile_last_name are simple text fields.

The Format of the field in the View is set to "Raw".

Thanks for looking into this issue.

hansfn’s picture

The lack of feedback is caused by me being on vacation.

I'm not surprised that a Computed Field field doesn't work. I'll have to look at this after my vacation - in the beginning of August. I of course accept patches ;-)

roball’s picture

Thank you for looking into it after your vacation. I can ensure that the same Computed Field field did work in an earlier devshot of Views Send, but stopped to work some times ago (don't know with which change, however).

hansfn’s picture

Title: views-send- Token is replaced by an empty string » Token replacement doesn't work for Computed Field fields.
Version: 6.x-1.0-alpha1 » 6.x-1.x-dev
hansfn’s picture

Hm, I just tested with a computed field named field_computed and the token replacement just worked. (I assume you have checked the "Store using the database settings below (required for Views use)" for the field?) Maybe flushing the cache helps? Or maybe you have some other modules causing problems?

If you use the devel module, you can add

dpm($context['views_send_tokens']);
dpm($context['row']);

in the beginning of the function views_send_mail_action (for example around line 315) to see what tokens Views Send know about and what info Views Send gets from Views. Please post the output here.

hansfn’s picture

Status: Active » Postponed (maintainer needs more info)

@roball: Is this problem still present in the latest dev version (2012-Aug-16 or newer)?

roball’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta1

With beta1, [views-send-field_profile_full_name] will still be replaced by an empty string, so, yes, the problem is still present.

dpm($context['views_send_tokens']);

gives

... (Array, 13 elements)

    counter (String, 7 characters ) counter
    field_profile_first_name_value (String, 24 characters ) field_profile_first_name
    field_profile_last_name_value (String, 23 characters ) field_profile_last_name
    field_profile_full_name_value (String, 23 characters ) field_profile_full_name
    edit_node (String, 9 characters ) edit_node
    users_name (String, 4 characters ) name
    users_mail (String, 4 characters ) mail | (Callback) mail();
    location_node_data_field_location_address_country (String, 7 characters ) country
    field_member_icc_value (String, 16 characters ) field_member_icc
    users_uid (String, 3 characters ) rid
    field_profile_icc_oo_value (String, 20 characters ) field_profile_icc_oo
    users_status (String, 6 characters ) status
    users_login (String, 5 characters ) login

so there is actually nothing being replaced.

However,

dpm($context['row']);

works - it gives

... (Object) stdClass

    nid (String, 3 characters ) 445
    node_data_field_profile_first_name_field_profile_first_name_value (String, 6 characters ) Robert
    node_type (String, 7 characters ) profile
    node_vid (String, 3 characters ) 448
    node_data_field_profile_first_name_field_profile_last_name_value (String, 12 characters ) Allerstorfer
    node_data_field_profile_first_name_field_profile_full_name_value (String, 19 characters ) Robert Allerstorfer
    users_uid (String, 1 characters ) 1
    users_name (String, 6 characters ) roball
    users_mail (String, 29 characters ) robert.allerstorfer@example.com
    location_node_data_field_location_address_country (String, 2 characters ) at
    users_status (String, 1 characters ) 1
    users_login (String, 10 characters ) 1346937582
hansfn’s picture

Status: Needs review » Active

Hi, roball

It's a little bit annoying that you didn't test this when I asked back in August. The beta1 was released because this and similar bugs should have been fixed for good. Apperently they weren't.

Anyway, your dpm output above is correct/perfect. $context['views_send_tokens'] doesn't contain the replacements - just the tokens and keys. However, I see now that the fix I applied to _views_send_get_fields_and_tokens _views_send_get_from_views_result wasn't duplicated to views_send_mail_action. I'll be back tonight with a fix. Being confident now ;-)

roball’s picture

Status: Postponed (maintainer needs more info) » Active

Sorry for reporting back too late - will try your fix asap.

hansfn’s picture

Status: Active » Needs review
FileSize
1.17 KB

I'm 99,99% sure that the attached patch will solve your problems. Please test.

hansfn’s picture

Title: Token replacement doesn't work for Computed Field fields. » Token replacement doesn't work
Status: Active » Fixed

Fixed in commit 1d98b38.

roball’s picture

Yeah, I can confirm that it finally works with 6.x-1.0-beta2. Thanks for the fix!

hansfn’s picture

Status: Fixed » Closed (fixed)

Thx for confirming. I'm closing this now.