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?

CommentFileSizeAuthor
#7 Screen shot 2011-04-19 at 09.25.17.png9.11 KBkenorb

Comments

kenorb’s picture

I see as well that value is already changed to mine on hook_views_post_render.
But output doesn't contain that value.

kenorb’s picture

See following screenshots:
Only local images are allowed.

Only local images are allowed.

Only local images are allowed.

Only local images are allowed.

merlinofchaos’s picture

Status: Active » Closed (works as designed)

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

kenorb’s picture

I 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()

kenorb’s picture

Title: Can't rewrite Custom Text or tid_1 value on hook_views_pre_render » Can't rewrite tid_1 value on hook_views_pre_render

I 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:

SELECT term_data.tid AS tid FROM term_data term_data 

now tid is part of the query

kenorb’s picture

Test 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:

/* Field: Taxonomy: Term ID */
$handler->display->display_options['fields']['tid_1']['id'] = 'tid_1';
$handler->display->display_options['fields']['tid_1']['table'] = 'term_data';
$handler->display->display_options['fields']['tid_1']['field'] = 'tid';
$handler->display->display_options['fields']['tid_1']['alter']['alter_text'] = 1;
$handler->display->display_options['fields']['tid_1']['alter']['text'] = '([tid_1])';
$handler->display->display_options['fields']['tid_1']['alter']['make_link'] = 1;
$handler->display->display_options['fields']['tid_1']['alter']['path'] = 'node/[tid_1]';
$handler->display->display_options['fields']['tid_1']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['external'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['tid_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['tid_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['tid_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['tid_1']['element_label_colon'] = 1;
$handler->display->display_options['fields']['tid_1']['element_default_classes'] = 1;
$handler->display->display_options['fields']['tid_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['tid_1']['empty_zero'] = 0;
$handler->display->display_options['fields']['tid_1']['format_plural'] = 0;

Using following hook:

function hook_views_pre_render(&$view) {
  switch($view->name) {
    case 'Test':
      foreach($view->result as $index => &$result) {
        $result->tid_1 = 123;
      } 
      // var_dump($view->result);
      break;
  }
}

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.

kenorb’s picture

Title: Can't change value on hook_views_pre_render » Can't rewrite tid_1 value on hook_views_pre_render
Status: Closed (works as designed) » Active
StatusFileSize
new9.11 KB
kenorb’s picture

Title: Can't rewrite tid_1 value on hook_views_pre_render » Can't rewrite Custom Text or tid_1 value on hook_views_pre_render
kenorb’s picture

Title: Can't rewrite tid_1 value on hook_views_pre_render » Can't rewrite Custom Text or tid_1 value on hook_views_pre_render
Status: Active » Fixed

Ok, at least overridden weight works, I'm happy with that. Thanks for your help.

Status: Fixed » Closed (fixed)

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