Today I edited a page and got many errors as follow:

notice: Array to string conversion in .../drupal/sites/all/modules/token/token.module on line 280.

I printed some debug to see what happens, there are 4 entries that are saved in the $full->values array as array instead of strings.

  // from $tokens
  [92]=>
  string(10) "[menupath]"
  [93]=>
  string(14) "[menupath-raw]"

  [158]=>
  string(10) "[termpath]"
  [159]=>
  string(14) "[termpath-raw]"

  // from $full->values
  [92]=>
  array(1) {
    [0]=>
    string(25) "Ubuntu Versions and Names"
  }
  [93]=>
  array(1) {
    [0]=>
    string(25) "Ubuntu Versions and Names"
  }

  [158]=>
  array(1) {
    [0]=>
    string(8) "Articles"
  }
  [159]=>
  array(1) {
    [0]=>
    string(8) "Articles"
  }

The two are created in this way because of pathauto.

In pathauto.module, we have those for the termpath[-raw] variables:

        $values[$label . 'path'] = !empty($options['pathauto']) ? $catpath : implode('/', $catpath);
        $values[$label . 'path-raw'] = !empty($options['pathauto']) ? $catpath_raw : implode('/', $catpath_raw);

And in token.module, we've got those two for the menupath[-raw]:

      $values['menupath']            = !empty($options['pathauto']) ? $trail : implode('/', $trail);
      $values['menupath-raw']        = !empty($options['pathauto']) ? $trail_raw : implode('/', $trail_raw);

Was pathauto expected to do something about these in token_prepare_tokens()?

That would not be possible since the $full->values is not passed down, but I was wondering if that's what was expected before and it would have changed? At this time, it looks like we should remove these special tests and just use the string generated by the right hand side.

Thank you.
Alexis Wilke

Comments

dave reid’s picture

That is what the pathauto_clean_token_values() function does, yes. But I think I see what's happening. We're not caching tokens based on $options! GAH.

dave reid’s picture

Title: Token values defined as array and kept all the way » Improve token generation and caching
Assigned: Unassigned » dave reid
dave reid’s picture

Status: Active » Needs review
StatusFileSize
new5.34 KB
dave reid’s picture

And testing that the added test should actually *fail*.

Status: Needs review » Needs work

The last submitted patch, 1174472-token-improve-generate-cache-fail.patch, failed testing.

dave reid’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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