Download & Extend

Block dont appear if vocabulary id is greater than 9

Project:Taxonomy Blocks
Version:6.x-1.0-beta1
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

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

instead of

<?php
$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 ?

Comments

#1

My changes are to put line 21 in taxonomy_blocks.module

#2

Status:active» patch (to be ported)

#3

I'll try :

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

best,

opi

#4

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 :-) ...)

#5

@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

#6

Status:patch (to be ported)» needs review

why are we trying to make this complicated ?

solution from comment 1 works

here is a patch, please apply and review

AttachmentSize
617186_taxonomy_blocks.module.patch 749 bytes

#7

Status:needs review» fixed

Works for me, committed.

#8

Status:fixed» closed (fixed)

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