I have experienced a very strange behaviour of Drupal 7. I had Devel module activated, and a View which made the sql logs to disappear from screen. The view was used by views_get_view_result()
. When I have changed the exact code to use views_embed_view()
, with the same and exact rendering, the SQL logs started to appear again.
Is there some Drupal 7 expert (ninja level suspected) out there that can understand what could happen? The bug was consistent, it always happened in the same View config (I replicated different Views with different names and the behaviour always appeared at the same point).
The configuration that caused the problem was:
- Field collection
- View with field collection
- Contextual filter (here it started to ignore sql log output)
- Call to the function views_view_result. Even the call itself, without using the value, caused the problem.
Solution: Call views_view_embed()
instead. No problem anymore. Same contextual filters, and blocks used. Exact configuration and exact output than views_view_result()
.
Note: I need an explanation of why this is happening, and a possible solution. The output of the SQL logging is not sent to the HTML source output of the page.
Code used. The commented lines do not work, and are substituted by the non-commented lines above them. The function is supossed to return an integer.
function sacar_numero_productos($id_categorias, $marca){
$marca = str_replace("/", "", $marca);
$a = views_embed_view("numero_productos", "block_1", $id_categorias, $marca);
// LINE BELOW DOES WORK BUT DESTROYS THE OUPUT OF SQL QUERIES
//$a = views_get_view_result("numero_productos", "block_1", $id_categorias, $marca);
return (int)(trim(strip_tags($a)));
// IF I USE views_get_view_result, this is the return value instead.
/*if(isset($a[0]->field_data_field_id_unico_oem_field_id_unico_oem_value) && (int)$a[0]->field_data_field_id_unico_oem_field_id_unico_oem_value > 0){
return (int)$a[0]->field_data_field_id_unico_oem_field_id_unico_oem_value;
} // if*/
return 0;
} // function
views_get_view_result
notviews_view_result
.views_get_view_result
isn't used anywhere so I'm guessing you have some custom code doing this. The SQL output you are referring to, is that what is possible to enable from devel module? Did you check that the markup is missing (that it's not a styling issue)?views_get_view_result
(thanks for the correction), and it is working in the last D7 version. The output source is not delivered, it is not a problem of styles. And yes, the output sql is what is delivered when you check the "Display query log" option.