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'),
    );
CommentFileSizeAuthor
#6 1020100-token-validate-all.patch3.21 KBDave Reid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hass’s picture

Title: token_element_validate_token_context complains on valid tokens like [current-user:roles] » token form validation complains on valid tokens like [current-user:roles]
Dave Reid’s picture

Status: Active » Fixed

Use the latest 7.x-1.x-dev of token please.

hass’s picture

Status: Fixed » Active
; Information added by drupal.org packaging script on 2010-12-15
version = "6.x-1.x-dev"
core = "6.x"
project = "token"
datestamp = "1292372764"
; Information added by drupal.org packaging script on 2010-12-18
version = "7.x-1.x-dev"
core = "7.x"
project = "token"
datestamp = "1292675134"

There are no newer versions... I have installed both DEVs tonight!

hass’s picture

Status: Active » Fixed

hell, it is fixed... must have been tooooo late tonight.

hass’s picture

Title: token form validation complains on valid tokens like [current-user:roles] » token form validation complains on valid tokens like [user:picture]
Status: Fixed » Active

Found 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]."

    $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_types' => array('all'),
    );

As I'm using token_tree with 'all' and it also shows me the 'user' tokens... so users may select them.

  $form['googleanalytics_custom_var']['googleanalytics_custom_var_token_tree'] = array(
    '#theme' => 'token_tree',
    '#token_types' => 'all',
  );
Dave Reid’s picture

Status: Active » Needs review
FileSize
3.21 KB

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

Dave Reid’s picture

Follow-up fixed filed in GA with #609892: Multiple custom variables.

Dave Reid’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Committed #6 to 7.x-1.x.
http://drupal.org/cvs?commit=479634

Dave Reid’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Fixed

Fixed on 6.x-1.x as well.
http://drupal.org/cvs?commit=479658

hass’s picture

Are 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.

Dave Reid’s picture

Using 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').

Status: Fixed » Closed (fixed)

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