I've created simple view based on Taxonomy with two following fields: 'Term ID' and 'Custom Text'.
I've rewritten Link path and Text, using token: [nothing]
Now I'm trying to change output of 'Custom Text' during hook_views_pre_render by following code, but it doesn't work.
function hook_views_pre_render(&$view) {
switch($view->name) {
case 'Test':
foreach($view->result as $index => &$result) {
$result->nothing = 'it_works';
}
// var_dump($view->result);
break;
}
}
It changes value correctly, the code was working when I used with terms_count_data module, but it doesn't work with most of the fields.
Here is a simple view:
$view = new view;
$view->name = 'Test';
$view->description = '';
$view->tag = '';
$view->base_table = 'term_data';
$view->human_name = 'test';
$view->core = 6;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Taxonomy: Term ID */
$handler->display->display_options['fields']['tid']['id'] = 'tid';
$handler->display->display_options['fields']['tid']['table'] = 'term_data';
$handler->display->display_options['fields']['tid']['field'] = 'tid';
$handler->display->display_options['fields']['tid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['tid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['tid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['tid']['alter']['external'] = 0;
$handler->display->display_options['fields']['tid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['tid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['tid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['tid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['tid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['tid']['alter']['html'] = 0;
$handler->display->display_options['fields']['tid']['element_label_colon'] = 1;
$handler->display->display_options['fields']['tid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['tid']['hide_empty'] = 0;
$handler->display->display_options['fields']['tid']['empty_zero'] = 0;
$handler->display->display_options['fields']['tid']['format_plural'] = 0;
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = 'Test';
$handler->display->display_options['fields']['nothing']['alter']['text'] = '([nothing])';
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['path'] = 'test/[nothing]';
$handler->display->display_options['fields']['nothing']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['external'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['html'] = 0;
$handler->display->display_options['fields']['nothing']['element_label_colon'] = 1;
$handler->display->display_options['fields']['nothing']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nothing']['hide_empty'] = 0;
$handler->display->display_options['fields']['nothing']['empty_zero'] = 0;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'test';
Why it doesn't work as expected?
Comments
Comment #1
kenorb commentedI see as well that value is already changed to mine on hook_views_post_render.
But output doesn't contain that value.
Comment #2
kenorb commentedSee following screenshots:




Comment #3
merlinofchaos commentedGlobal: Custom Text does not add anything to the query, and thus does not read anything from $resut. It simply uses the value in the handler. I'm not sure why you'd even expect it to read anything from the result.
Comment #4
kenorb commentedI tried with Term ID, Node ID, and there is the same problem.
I was expecting to change the data how is displayed on pre_render()
Comment #5
kenorb commentedI described my problem using wrong example.
Test 2
I've tested on the same view.
Rewritten output to: ([tid])
Link to: node/[tid]
It does work.
My query:
now tid is part of the query
Comment #6
kenorb commentedTest 3
But it doesn't work for the next 'Term ID': tid_1
Details:
The same view. Instead of 'Custom text', there is new field:
Using following hook:
the second value is not rewritten (I see the change in post_render).
But instead of my rewritten tid_1 I see tid.
It's the same issue, that second tid_1 is not in the query, even the first tid is?
Test 4
Tested with weight (term_data_weight), it does work.
Sorry, I'm just confused. My main goal was to find any field which I can simply rewrite the output.
Comment #7
kenorb commentedComment #8
kenorb commentedComment #9
kenorb commentedOk, at least overridden weight works, I'm happy with that. Thanks for your help.