Using PHP 7 I am seeing the following notice:

Notice: Array to string conversion in _token_token_tree_format_row() (line 207 of .../modules/contrib/token/token.pages.inc).

Code is setting $row['data']['name']['class'] as an array, but expecting a string.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

smulvih2 created an issue. See original summary.

smulvih2’s picture

Patch to remove notice.

smulvih2’s picture

Here is a new patch that fixes other issues with the _token_token_tree_format_row() function with regards to PHP 7 and setting arrays properly.

smulvih2’s picture

Title: Array to string conversion in _token_token_tree_format_row() » Array to string conversion in _token_token_tree_format_row() - PHP 7
Issue summary: View changes
joseph.olstad’s picture

Status: Active » Reviewed & tested by the community

Le correctif fonctionnent.
php 7.4 sera prise en charge par Drupal core 7.71, dépêchons nous, pousse ce code ! c'est prêt.

Dave Reid’s picture

Version: 7.x-1.7 » 7.x-1.x-dev
Status: Reviewed & tested by the community » Closed (duplicate)
Related issues: +#2825841: Error : Cannot use string offset as an array in _token_token_tree_format_row()

Neither patch applies to the module currently. I believe this was fixed by #2825841: Error : Cannot use string offset as an array in _token_token_tree_format_row()?

joseph.olstad’s picture

Status: Closed (duplicate) » Needs review

@Dave Reid ,
that patch related issue was over 4 years ago, the above patch is 9 months ago.

I think this above patch is still needed

Dave Reid’s picture

Status: Needs review » Needs work

The patch above does not apply to the current code at all, I will need an updated patch that does apply in order to fix it. There is no section of code that has $row['data']['name']['class'] = array('token-name');

joseph.olstad’s picture

joseph.olstad’s picture

Status: Needs work » Needs review

Try this

Dave Reid’s picture

@@ -199,6 +205,7 @@ function _token_token_tree_format_row($token, array $token_info, $is_group = FAL
   $row = $defaults;
   $row['id'] = _token_clean_css_identifier($token);
   $row['data']['name'] = $token_info['name'];
+  $row['data']['name']['class'][] = 'token-name';

Two questions on this:

1. Isn't $row['data']['name'] an array now with the patch, and this is now trying to set it to a string?
2. Why adding the class? I don't necessarily mind it but this seems to be new and I'm just curious as to why it's being added here. This was part of my original confusion about the other patches.

joseph.olstad’s picture

wasn't sure about that line, was just trying to reroll the patch
I know I did need the patch as it was prior