This module work fine with queries as text but I have a query as array e.g. mydomain/page?field_ccaa[]=231 and doesn't work.
I want the block doesn't appear in a page with this query. This query is show in browser mydomain/page?field_ccaa%5B%5D=231. I try with field_ccaa[]=231, field_ccaa%5B%5D=231, *=* but doesn't work.
Coul you help me with this?
Thanks.

Comments

SolomonGifford’s picture

I assume you've tried

*=231

That said - I bet the encoding is the issue. If you wants to take a crack at a fix, I can test..or I can address next week sometime (hopefully).

manucuest’s picture

Yes, I tried *=231 also and doesn't work.
I can't help with this issue, sorry.
Thanks a lot.

manucuest’s picture

I don't have a deep knowledge of Drupal'a API but I'm found a solution for this problem, in my project at least.
The block_query.module file has at line 141 a conditional that evalue querystring parameters for function block_query_block_list_alter(), well this parameters appear empty if the parameter is a array. At the end of this conditional (line 149) I added:

else {
if(!is_array($getkey) and is_array($value)){
$getkeylower = drupal_strtolower($getkey);
$valuelower = drupal_strtolower($value[0]); //This variable take the first value of array

if ($getkeylower != 'q' && !$page_match) {
$page_match = drupal_match_path($getkeylower . '=' . $valuelower, $queries);
}
}
}

Note that $valuelower take the first item of array. This work for me because I need show the block when the URI doesn't have any querystring.

This is a useful module and I hope this code help to improve it.

Thanks a lot.

SolomonGifford’s picture

Status: Active » Needs work

Can you provide a patch?

kala4ek’s picture

Component: Miscellaneous » Code
Status: Needs work » Needs review
StatusFileSize
new830 bytes

Patch provided.

pebosi’s picture

Status: Needs review » Reviewed & tested by the community

Patch works for me, thanks!

dangur’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new610 bytes

I believe this solution is more elegant as it does not duplicate code.

linitrex’s picture

StatusFileSize
new1.17 KB

#7 is not a general solution. It is a workaround for one of the very simple cases when having single dimension array. One may have not only array but also array of arrays, array of array of arrays etc. The whole function function block_query_block_list_alter(&$blocks) should be replaced I think . Instead of converting _GET to keys/values and cheeking for queries my proposal is to convert the queries and _GET to URL format and then check if the converted _GET string contains the converted queries string.

function block_query_block_list_alter(&$blocks) {
global $theme_key;

// Build an array of terms for each block.
$block_queries = array();
$result = db_query('SELECT module, delta, visibility, queries FROM {block_query}');
foreach ($result as $record) {
$block_queries[$record->module][$record->delta] = $record->queries;
$block_visibility[$record->module][$record->delta] = $record->visibility;
}
foreach ($blocks as $key => $block) {
if (!empty($block_queries[$block->module][$block->delta])) {

// Convert path to lowercase. This allows comparison of the same query
// with different case.
$page_match = FALSE;
$queries = drupal_strtolower($block_queries[$block->module][$block->delta]);

$queries_as_url=str_replace("%3D", "=", urlencode($queries));
$_GET_as_url=http_build_query($_GET);
$page_match=strpos($_GET_as_url,$queries_as_url);

if (!$page_match) {
unset($blocks[$key]);

// When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
// the block is displayed on all pages except those listed in
// $block->pages.
//
// When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those
// pages listed in $block->pages.
$page_match = !($block_visibility[$block->module][$block->delta] xor $page_match);
if (!$page_match) {
unset($blocks[$key]);
}
}
}
}
}