4

I have a (Apache solr) view with a Global: Custom text field in addition to my normal fields. This field is meant to get value from a custom function/existing field/passing an existing field to a custom function and using return value in one of my modules per each result and I am trying to accomplish this functionality without using Views PHP module.

I referred this very similar query and tried the following approach which did not yield me the result:

hook_views_pre_render:

function mymod_views_pre_render(&$view) {
  if ($view->name == 'mymodview' && $view->current_display == 'mymod_display') {
    $result = &$view->result;
    foreach ($result as $num_idx => $result_obj) {
      $result[$num_idx]->nothing = $result_obj->an_already_available_field_or_fxn_call;
    }
  }
}

Also tried the same code with hook_views_post_execute to no avail. Using $view->field['nothing']->options['alter']['text'] = 'My custom text'; set the default text value to all fields which was not my desired result.

Based on the post linked earlier tried the following code in my theme's template.php

template_preprocess_views_view_fields:

function mytheme_preprocess_views_view_fields(&$vars) {
  $view = $vars['view'];
  if ($view->name != 'mymodview' && $view->current_display != 'mymod_display') {
    return;
  }
  foreach ($view->field as $id => $field) {
    $vars['fields']['nothing']->content = 'Some global custom text content';
  }
}

I am unable to determine what I am missing out on owing to my relative inexperience with views functionality and guidance on achieving this programatically would be much appreciated.

2 Answers 2

0

have you tried to use a custom handler? This way you don't need to override nothing.

Related to: Move php in views to module

0

If you are trying to change the value of the global text is quite simple. You have to use the one of the views hook.

function YOUR_MODULE_views_post_execute(&view)
{
   // You can change the value like this, if you have mutliple result you might want to wrap this inside a foreach loop. 
   $view->field['nothing']->options['alter']['text'] = 'updated via php';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.