After updating to the latest version of token today, all the custom breadcrumbs stopped working and I started getting the following message:


warning: preg_match_all() expects parameter 2 to be string, array given in [snip]/sites/all/modules/token/token.module on line 705.

After initially thinking this was a bug with token module and supplying a patch to fix it here - #1307890: token_replace() performance when there are no tokens - it turns out that token_replace accepting arrays was unintended functionality that was never meant to be supported and now that there is a performance fixup stopping array input, the module will not work.

So, the fix now is change custom_breadcrumbs_nodeapi() to call token_replace with only strings.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ELC’s picture

Status: Active » Needs review
FileSize
1.68 KB

Attached is a patch that does just that. It also reduxes the calling of token replace to only parts that it's using.

betovarg’s picture

ah man... i just updated token and i get "warning: preg_match_all() expects parameter 2 to be string, array given in /Applications/MAMP/htdocs/manati/sites/all/modules/token/token.module on line 701."

Can anyone confirm the patch works?

djmolny’s picture

For now, I opted to go with ELC's patch of the token module itself. And yes, that fixed my problem.

Danny_Joris’s picture

I have this issue in the 6.2-dev branch. The code is different.

Patrizio’s picture

This is the code for the 6.x-2.0-rc1 version

  // Token replacement for titles and paths
  if (module_exists('token')) {
    // Do token replacement.
    $types = custom_breadcrumbs_token_types($objs);
    #PB:20111102 foreach on titles and paths because il token_replace_multiple require a string
    foreach($titles as $key => $value) {
        $titles[$key] = token_replace_multiple($value, $types);
    }
    foreach($paths as $key => $value) {
        $paths[$key] = token_replace_multiple($value, $types);
    }
    #\PB:20111102
  }
  $items = _custom_breadcrumbs_get_trail_items($breadcrumb, $titles, $paths);
emi_bcn’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Hi there,

I have same problem here. Confirmed that the patch solves the bug.

Changed the attributes so module maintainer knows what's happening.

bohz’s picture

Thanks, @Patrizio.
#5 works flawlessly

kaare’s picture

Here's the patch as a .patch ;-)

Indentation fixed to adhere drupal coding style.

MGN’s picture

Thanks to everyone for helping on this. I'll review it and commit as soon as I get a free moment (now where did I leave it...)

fzipi’s picture

I can also confirm that patch solves bug.

fchandler’s picture

Having the same problem in 6.x-1.5 of custom breadcrumbs and token 6.x-1.17, 1.18 and 1.dev. I will try the patch. Albeit, i will have to learn how to apply a patch. The other part of that is not having command line access on shared hosting sites. Then there is the problem of running a dev version on a production site, which is something I have been told not to do. So at this point it looks like I have few options other than not updating the Token module or disabling the Custom Breadcrumbs module. Any suggestions?

basvredeling’s picture

I can confirm patch #8 too. It works fine.

andrewsuth’s picture

Patch #8 works for me too. Nice work.

Boobaa’s picture

Version: 6.x-1.x-dev » 6.x-1.5
Status: Reviewed & tested by the community » Needs review
FileSize
887 bytes

Here is the patch for the latest 6.x stable version.

ntg’s picture

Thank you. Patch #8 worked (for 6.x-2.x-dev).

stijnbe’s picture

Patch #14 worked for me, thanks.

killua99’s picture

ahimsauzi’s picture

Same here for #5! Thanks @Patrizio

szt’s picture

#5 (and #8) works for 6.x-2.0-rc1!
Patrizio++

ehudash’s picture

Patch #8 worked for me (function _custom_breadcrumbs_get_breadcrumb)
Thanks kaare!

eL’s picture

Patch #8 worked for me (for 6.x-2.0-rc1)

Chad_Dupuis’s picture

Patch in #14 for the 6.x-1.5 version did not work for me... I still get the following after patching, updating and clearing all caches...

User notice: The custom_breadcrumbs_nodeapi() function called token replacement with an array rather than a string for $text in token_replace_multiple() (line 263 of /.../sites/all/modules/token/token.module).

ELC’s picture

The author of Token has insisted that everyone is wrong for using arrays and refused to update the API.

As a result, since 1.18 you now get a warning any time a module uses an array instead of text, instead of a flat our error.

I'm going to open a feature request on Token to update the API documentation, return to the efficient handling of arrays, and remove the warning. Just haven't got around to it yet since it will need to be a rather long request.

You can remove the error being written to the logs by removing the line of code from the Token module. I haven't looked at it to see where it is yet.

Dave Reid’s picture

A quick update on this from the token maintainer (me): I'm officially backtracking on not supporting $text being an array. I looked back and as of 6.x-1.15 the token_replace() functions officially had it documented that $text could either be a string or an array. This reference to it being an array was removed when I updated the documentation for the functions which I had assumed the array reference was a mistake (which was my fault). At this point in 6.x-1.x-dev (and eventually in the future 6.x-1.19 release) of Token there are no more warnings thrown if $text is an array and token replacement should just work as before. I apologize to the end users of Token who encountered those frustrating notices and the module developers who had these bugs reported against their modules. This experience was at least valuable to know which modules were using array token replacement as they would have encountered this problem when porting modules to Drupal 7. Also, in the official API documentation, $text is a string. The parameter being an array is only supported for backwards-compatibility.

That said, this patch should still probably be committed.

wjackson’s picture

Patch #14 works for me in 6.x-1.5. Thanks Boobaa!

monotaga’s picture

Patch at #8 worked for me on 6.x-2.0-rc1.

szt’s picture

Status: Needs review » Reviewed & tested by the community
eiland’s picture

I applied path #5 to 2.0 rc and now I don't have an error anymore but my path now reads

"Home › [i18n-vocab] › [i18n-cat] > Title"

Setting is
(Titles: [i18n-vocab]
[i18n-cat]
Paths:
|[vocab-raw]
/[termalias]

WTF?

killua99’s picture

@eiland: rewrite yours settings. And tell us if that works.

eiland’s picture

i unstalled the module and enabled it again. The brackets are gone, but the functionality didn't return to normal, as I expected it to. I saw the tokens were missing, and i remembered I once patched pathauto.

So I now believe my problem might be due the recent update of pathauto and the lacking i18n integration @#290421: pathauto patch to provide localized and entity translated taxonomy through i18n.

iantresman’s picture

For anyone else that is not able to handle, or can not read patch files, the following worked for me for Custom Breadcrumbs 6.x-1.5:

  1. In the custom_breadcrumbs folder, look for and open the file: custom_breadcrumbs.module
  2. Search for the two lines:
          $titles = module_exists('token') ? token_replace($titles, 'node', $node) : $titles;
          $paths = module_exists('token') ? token_replace($paths, 'node', $node) : $paths;

    and "rem" them out by adding two slashes at the beginning of the lines:

          //$titles = module_exists('token') ? token_replace($titles, 'node', $node) : $titles;
          //$paths = module_exists('token') ? token_replace($paths, 'node', $node) : $paths;
  3. Immediately after these two lines, add the following:
          if (module_exists('token')) {
            foreach ($titles as $key => $value) {
              $titles[$key] = token_replace($value, 'node', $node);
            }
            foreach ($paths as $key => $value) {
              $paths[$key] = token_replace($value, 'node', $node);
            }
          }
  4. Save the file and upload it. There's no need to do a "update", and it should fix the problem immediately.
ryansnow’s picture

Thank you. This worked perfectly for me.

FiNeX’s picture

Patch #8 works fine on Custom breadcrumbs 6.x-2.0-rc1. Thanks.

bomarmonk’s picture

Patch in #8 solved my issue: 6.x-2.0-dev. Thanks!

ngstigator’s picture

thanks, patch #8 works for 6.0-rc1.

chris

Lucada’s picture

...also for me!

joep.hendrix’s picture

patch #8 works for 6.x-2.x-dev 2011-Jul-16

venusrising’s picture

Patch 8 does not work for us for 6x-2 rc1 we still get Db errors. Does anyone know where to go from here?

venusrising’s picture

Status: Reviewed & tested by the community » Active
venusrising’s picture

Dave thanks for the reply.
The question is, do you know how to fix this or prevent the massive log pile up in Custom Breadcrumbs 6x2RC1 we have a production site filling up logs. We would be willing to pay for some help.

venusrising’s picture

@FiNeX How did you get the patch to work? I installed patch but I still get the DB errors filling up.
Thanks for your help. Running same version as you 6x2RC1

MGN’s picture

Status: Active » Closed (fixed)

Thanks everyone. I agree the patch in #8 is the way to go. Committed to 6.x-1.x-dev. If you still have a problem after trying the latest 6.x-1.x-dev release, please open another issue.

MGN’s picture

Status: Closed (fixed) » Fixed
MGN’s picture

Note: I also committed the fix (more or less) in #5 by Patrizio to the 6.x-2.x-dev branch.

venusrising’s picture

Status: Fixed » Active

@MGN sorry to reopen but can you tell us what may work with the 6x2 RC1 as we have it on a production site since it has the views integration and is working great for us with the exception of the DB errors

ressa’s picture

Patch in post #8 also works for version 6.x-2.0-rc1, thanks.

venusrising’s picture

@ressa we tried the patch but could not get it to work, what did you do to get it to work, we also are running same version as you.

ressa’s picture

@venusrising: I patched it manually in the file, not via the terminal. I know it's not the right way to do it, but I figured the bug would be fixed in the next release, and the changes were minor. Perhaps the patch is made for another version with different line numbers, and that's why it worked for me, but not for you?

sin’s picture

From #1341138: called token replacement with an array rather than a string for $text,

the error "user notice: The custom_breadcrumbs_nodeapi() function called token replacement with an array rather than a string for $text in /sites/all/modules/token/token.module on line 263." is fixed using token 6.x-1.x-dev

caspercash’s picture

#8 solved my problem! Thanks! Token module version is 6.x-1.18

TwoD’s picture

Status: Active » Reviewed & tested by the community

The #8 patch worked for me as well.

carlop’s picture

Patch #8 worked for me too, thanks.

sw3b’s picture

#8 work for me too !!!

opegasus’s picture

Only AWESOME

iantresman !!!

Thanks, worked perfectly for me! I had to dig a little since the code was a wee bit different in the latest dev of this module but it killed printing of the token glitch right away. Glad I scrolled though the thread.

I hope the changes don't screw anything else up but time will tell. Since I am not a 'developer', answers like yours are a life saver, thanks again.

Thomas_Zahreddin’s picture

this issue is a duplicate to http://drupal.org/node/1333878 and in 1333878 solved.

This is solved (according to the commit message) with

http://drupalcode.org/project/custom_breadcrumbs.git/commit/f6ee1aa

If you want to get the actual code download any version newer then

custom_breadcrumbs 6.x-2.0-rc1

and meanwhile you can use the -dev - version

http://drupal.org/node/417124

for drush: drush dl custom_breadcrumbs-6.x-2.x

wuiler’s picture

Patch #8 worked for me, thanks.

mgifford’s picture

So Thomas_Zahreddin just want to confirm that there is no more support for the 1.x versions.

Looks like the upgrade is pretty simple. Any reason not to upgrade to the 2.x version?

Thomas_Zahreddin’s picture

well i listed all options to update to the version 2.x in #55

so you maybe want to close this issue as fixed?

mgifford’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Sure.. But your response in #55 doesn't clearly answer my question.

I will assume though that everyone should be encouraged to update to the 2.x version of the code.

bburg’s picture

Issue summary: View changes

The note in #55, that this issue is a duplicate to https://drupal.org/node/1333878 is not accurate because that issue was closed as a duplicate to this one in https://drupal.org/comment/5521980#comment-5521980.