Hello,

with the latest dev version I have this issue when I edit my profile where a namefield is placed.

Notice: Array to string conversion in token_replace() (line 102 of /var/www/wcity/includes/token.inc).

Thanks for any help!
Frank

Edit:
I see also there are tree tokens for the field. One is a double token an not usable I think. Maybe this is the problem?

Name	[user:field-name:?]	Field "field_name". The following properties may be appended to the token: title (The title of the name.), given (The given name.), middle (The middle of the name.), family (The family of the name.), generational (The generational of the name.), credentials (The credentials of the name.)

Name	[user:name-field-name]	Name field in the default format. To specify a delta value, use "field-name:0". Append the other chained options after the delta value like this, "field-name:0:component-given". Replace the delta value with all to obtain all items in the field like this "field-name:all".

Name	[user:field_name]	Name field.


Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan D.’s picture

There must be two modules giving the same token value for a particular token. The issue being, which module is clashing? And which one should get updated to prevent this?

So to speed this up, can you place the following on line 101 of that file and report the various messages that are returned. Refresh at least once on that page to ensure that all token messages are returned (to catch theme based tokens too)

drupal_set_message(var_export($replacements, 1));

Or if you do not have an editor, add this line towards the end of the function, just before the return statement:

function token_replace($text, array $data = array(), array $options = array()) {
....
  // Optionally alter the list of replacement values.
  if (!empty($options['callback']) && function_exists($options['callback'])) {
    $function = $options['callback'];
    $function($replacements, $data, $options);
  }

  $tokens = array_keys($replacements);
  $values = array_values($replacements);
#### This is the line that is added and should be deleted when finished. ####
drupal_set_message(var_export($replacements, 1));
  return str_replace($tokens, $values, $text);
}

Good results should look like this:
array ( '[current-domain:machine_name]' => 'maritime', )

Bad results would look something like this:
array ( '[current-domain:machine_name]' => array('maritime', 'maritime'), )

Alan D.’s picture

After just checking Profile2 and Realname modules, there are no clashes here, so it may be completely down to the Name field module generating two similar tokens....

This is the token help that I am getting for the user object with a name field without any restrictions on the tokens:

Name	[user:field-name:?]	Field "field_name". The following properties may be appended to the token: title (The title of the name.), given (The given name.), family (The family of the name.)
Name	[user:field_name]	Name field.
Name	[user:name-field-name]	Name field in the default format. To specify a delta value, use "field-name:0". Append the other chained options after the delta value like this, "field-name:0:component-given". Replace the delta value with all to obtain all items in the field like this "field-name:all".
Component: Credentials	[user:name-field-name:component-credentials]	The name component Credentials.
Component: Family	[user:name-field-name:component-family]	The name component Family.
Component: Generational	[user:name-field-name:component-generational]	The name component Generational.
Component: Given	[user:name-field-name:component-given]	The name component Given.
Component: Middle name(s)	[user:name-field-name:component-middle]	The name component Middle name(s).
Component: Title	[user:name-field-name:component-title]	The name component Title.
Formatted name: Family	[user:name-field-name:formatter-family]	Uses the Family format.
Formatted name: Full	[user:name-field-name:formatter-full]	Uses the Full format.
Formatted name: Given	[user:name-field-name:formatter-given]	Uses the Given format.
Formatted name: Given Family	[user:name-field-name:formatter-short_full]	Uses the Given Family format.
Formatted name: Title Family	[user:name-field-name:formatter-formal]	Uses the Title Family format.

[user:field-name:?] is from Entity Tokens module.
[user:field_name] is from the Token module.
[user:name-field-name????] are from the Name Field module.

fraweg’s picture

Title: Notice: Array to string conversion in token_replace() (line 102 of /.../includes/token.inc). » Notice: Array to string conversion in token_replace() (line 102 of /var/www/wcity/includes/token.inc).

Hello,

Thanks for your fast help!

So to speed this up, can you place the following on line 101 of that file and report the various messages that are returned. Refresh at least once on that page to ensure that all token messages are returned (to catch theme based tokens too)

You mean the token.inc file from the error message? If have done this and get this under "user/edit":

    array ( '[current-user:name-raw]' => array ( 0 => '', 1 => 'admin', ), '[current-user:uid]' => '1', )
    array ( '[current-user:uid]' => '1', )

I am not a developer so maybe I misunderstood something.

Edit:

I use Profile2 and Realname. So I deactivate the Realname module and the error is gone. But I want use the realname module :-( . With the last version "7.x-1.5" this error was not there, but the namefield did not work together with the Realname modul (The tokens does not work with Realname).

Best regards
Frank

fraweg’s picture

Title: Notice: Array to string conversion in token_replace() (line 102 of /var/www/wcity/includes/token.inc). » Notice: Array to string conversion in token_replace() (line 102 of /.../includes/token.inc).
Alan D.’s picture

Title: Notice: Array to string conversion in token_replace() (line 102 of /var/www/wcity/includes/token.inc). » Notice: Array to string conversion in token_replace() (line 102 of /.../includes/token.inc).
FileSize
5.94 KB

Right found the issue. When defining the tokens, I have taken the token namespace of "name-" and this directly clashes with the realname module token "name-raw".

A quick (untested) fix is to change this in the file name.token.inc around line 85:

  // This handles the field tokens.
  if (isset($data[$type]) && $known_tokens = name_token_types_chained($type)) {
    foreach ($tokens as $name => $original) {
      if (strpos($name, 'name-') === 0) {

to

  // This handles the field tokens.
  if (isset($data[$type]) && $known_tokens = name_token_types_chained($type)) {
    foreach ($tokens as $name => $original) {
      if ($name != 'name-raw' && strpos($name, 'name-') === 0) {

I will have to get my head into the chained token logic again before deciding on the best fix.

Since we are only dealing with fields here, I've added a second check to ensure that the token corresponds to an existing field. This will help reduce issues latter. So the patch contains the changes (one additional check on top of the above check) and I've pushed this into dev, but it will take up to 24 hours to roll.

Alan D.’s picture

Status: Active » Needs review

Even though there are no Token tests, this will re-run the other tests :)

fraweg’s picture

With the latest dev the error is gone and work together with the Realname module.
Thanks so much for your fast and great support!

Best regards
Frank

Alan D.’s picture

Status: Needs review » Fixed

Great news. Marking as fixed.

I will re-roll a new version soon that doesn't contain theme_name_component(), maybe an eta of 1 to 3 weeks.

Status: Fixed » Closed (fixed)

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

makokis’s picture

Project: Name Field » Token
Component: Miscellaneous » Code
Priority: Normal » Major
Status: Closed (fixed) » Needs work

i still with this issue yet.
Do you know how to solve this.

thanks

fraweg’s picture

Hello,

I use the actual stable token version an everything works fine for me. Which token do you use for the realname module an where did you place the field (profile2 or without profile2)?

Best regards
Frank

makokis’s picture

hi thanks,

I do no have install Profile2 and RealNames modules. I use Commerce Kickstart.
The token version is Token-7.x-1.4.

In the Status report i also have a problem with tokens:

" ...The following token or token types are defined by multiple modules:
$info['tokens']['commerce-order']['site-logo'] "

...and can't find nothing about it searching in drupal.org or google to solve.

fraweg’s picture

Hi,

ok I use it together with the Realname module.

" ...The following token or token types are defined by multiple modules:
$info['tokens']['commerce-order']['site-logo'] "

This issue must be fix in the comerce-order module. I this this is not a token issue. I had have it in Heartbeat module in the past (http://drupal.org/node/1281364) and it was solved there.

Maybe this is generally the problem in your issue.

Best regards
Frank

makokis’s picture

(http://drupal.org/node/1281364) and it was solved there.

reinstalling Heartbeat module looks solved it...

the errors i have:
1- http://www.screencast.com/t/Qqu9QfwTTL
2- http://www.screencast.com/t/OfmFDK7bNgWX

...in my case, i can't reinstall a single Commerce Kickstart module, only patch, because is part of the profile of Drupal 7, not an add-on module like Heartbeat.

in any case¡ a Happy New Year 201*
FELIZ AÑO NUEVO :)

fraweg’s picture

Hello,

the issue is back :-(
Now the conflict is in the new version of the module "Registration Password Token". I post the issue also there

http://drupal.org/node/1973974#comment-7355600

but there is no response.

Any idea in that ?

Best regards
Frank

fraweg’s picture

Hmm... no tip? :-(

Dave Reid’s picture

hoebekewim’s picture

This is a dirty fix that excludes wrong values passed into the token_replace().
Use it only as a last resort, this does not solve the issue but only disables the message !

Open token.inc and change the content of the function token_replace()

  ...
  return str_replace($tokens, $values, $text);

Change to:

  ...
  foreach($replacements as $value => $replacement){
      if((!is_array($value)) && (!is_array($replacement))&& (!is_array($text))){
          $text = str_replace($value, $replacement, $text);
      }
  }
  return $text;
Alan D.’s picture

Um. Token implements token_requirements() that should show warnings in the site status page. If it is complaining about something like:

...The following token or token types are defined by multiple modules:
$info['tokens']['commerce-order']['site-logo'] "

Search the code for the corresponding token values. Then open a new issue in each corresponding modules queue to get this resolved.

@Dave
Would it be useful to do something like this? not pretty but provides more context to discover the cause.

Alan D.’s picture

FileSize
3.93 KB

This was invoked by hacking the name module to insert a duplicate user picture token.

Alan D.’s picture

Issue summary: View changes

.