Hello
Block only appears if the vocabulary id is smaller tant 9. When its greater than 9 (10, 11 etc...), the regex from preg_replace only return 1 number -the first one. For example, for vocabulary 11, preg_replace return 1 and then module thinks he has to add a block for vocabulary id 1 instead of 11.

For the moment i put

  // Extract the vocabulary ID from the variable name
  $vid = str_replace('taxonomy_blocks_vid_','', $result->name);
  $vid = str_replace('_block_enabled','', $vid);

instead of

 $vid = preg_replace('/(\w+)(\d+)(\w+)/', '$2', $result->name);

I'm very bad with regular expressions, can someone tell me what's the best way to rewrite it, instead of using str_replace ?

CommentFileSizeAuthor
#6 617186_taxonomy_blocks.module.patch749 bytesgiorgosk

Comments

nyl_auster’s picture

My changes are to put line 21 in taxonomy_blocks.module

nyl_auster’s picture

Status: Active » Patch (to be ported)
opi’s picture

I'll try :

$vid = preg_replace('/(\w+)_(\d+)_(\w+)/', '$2', $result->name);

best,

opi

nyl_auster’s picture

This code works wonderfully : this one should be commited if possible :-)

$vid = preg_replace('/(\w+)_(\d+)_(\w+)/', '$2', $result->name);

Thanks Opi !
edit : could you explain me why the regex from the module is not able to catch two numbers, it seems correct to me... ( At least according to my poor acknowledges in regular expressions :-) ...)

opi’s picture

@nyl_auster :

\w Match a "word" character (alphanumeric plus "_"), so (\w+)(\d+)(\w+) match any alphanumeric string, with a mandatory numeric inside !

with _(\d+)_, we're looking for a numeric string between 2 undescores.

Another regex that works is : ([a-z_]+)_([0-9]+)_([a-z_]+).

For further informations, have a look here : http://php.net/manual/fr/function.preg-replace.php

opi

giorgosk’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new749 bytes

why are we trying to make this complicated ?

solution from comment 1 works

here is a patch, please apply and review

owahab’s picture

Status: Needs review » Fixed

Works for me, committed.

Status: Fixed » Closed (fixed)

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