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.
The #element_validate
fails to validate the valid [current-user:roles]
placeholder added by Google Analytics.
Error message is The Custom variable value #1 is using the following invalid tokens: [current-user:roles].
I'm using this form code:
$form['googleanalytics_custom_var']['slots'][$i]['value'] = array(
'#default_value' => !empty($googleanalytics_custom_vars['slots'][$i]['value']) ? $googleanalytics_custom_vars['slots'][$i]['value'] : '',
'#description' => t('The custom variable value. You may use tokens in this field.'),
'#title' => t('Custom variable value #@slot', array('@slot' => $i)),
'#title_display' => 'invisible',
'#type' => 'textfield',
'#element_validate' => array('token_element_validate_token_context'),
'#token_types' => array('all'),
);
Comment | File | Size | Author |
---|---|---|---|
#6 | 1020100-token-validate-all.patch | 3.21 KB | Dave Reid |
Comments
Comment #1
hass CreditAttribution: hass commentedComment #2
Dave ReidUse the latest 7.x-1.x-dev of token please.
Comment #3
hass CreditAttribution: hass commentedThere are no newer versions... I have installed both DEVs tonight!
Comment #4
hass CreditAttribution: hass commentedhell, it is fixed... must have been tooooo late tonight.
Comment #5
hass CreditAttribution: hass commentedFound user tokens are still not validating. I have also tried
'#token_types' => 'all'
, but this gave me some array errors. Message is "The Custom variable value #2 is using the following invalid tokens: [user:picture]."As I'm using token_tree with 'all' and it also shows me the 'user' tokens... so users may select them.
Comment #6
Dave ReidI never tried the validation using '#token_types' => array('all') before. But looking over the GA token_replace() code it only can provide node tokens + global token types. So the use of array('all') in the form field is incorrect. It really should be array('node') so that should be fixed upstream in the GA module. Regardless, there still is a problem with the validation.
Comment #7
Dave ReidFollow-up fixed filed in GA with #609892: Multiple custom variables.
Comment #8
Dave ReidCommitted #6 to 7.x-1.x.
http://drupal.org/cvs?commit=479634
Comment #9
Dave ReidFixed on 6.x-1.x as well.
http://drupal.org/cvs?commit=479658
Comment #10
hass CreditAttribution: hass commentedAre we able to make this consistent, please? If we use token_types in form element validation with array('all') i wish we also use an array in token_tree form element and not a string. I'd like to use 'all' in the token replece, too. Otherwise an 'all' in token_tree makes no sense to me.
Comment #11
Dave ReidUsing all does not work with token replacement. It never has. It's a display only option (used on the admin/help/token page to list all tokens on the site). If it doesn't make any sense to use (and since I've been trying to point out it's usage is wrong), then change it in your code to not use array('all').