0

I'm trying to change the value of a field in a view programatically but i find some problems.

  • first is that even though I created a Global: custom text field which field id is 'nothing', It's value remain unchanged and the value is applied to a new field created at the end of the view.

  • Second is that this function creates some errors and drupal send lots of notices:

Notice: Undefined property: stdClass::$wrapper_prefix in include() (line 32 of /my/path/sites/all/modules/views/theme/views-view-fields.tpl.php).

Notice: Undefined property: stdClass::$label_html in include() (line 33 of /my/path/sites/all/modules/views/theme/views-view-fields.tpl.php).

Notice: Undefined property: stdClass::$wrapper_suffix in include() (line 35 of /my/path/sites/all/modules/views/theme/views-view-fields.tpl.php).

My code is:

function real_estast_sub_preprocess_views_view_fields(&$vars) {
  $view = $vars['view'];

  foreach ($view->field as $id => $field) {

    // change the global custom text content depend on result (node id)
    if ($vars['row']->nid == 1625){
      $vars['fields']['nothing']->content = '666€';
    }else{
      $vars['fields']['nothing']->content = $vars['row']->field_data_field_price_field_price_value."€/noche ";
    }
  }
}

What's the problem here? I tried to follow all the steps explained in:

How to insert values into Global custom text field of views programmatically?

Edit: I soolved the notices form drupal by adding:

  $vars['fields']['nothing']->wrapper_prefix = '';
  $vars['fields']['nothing']->wrapper_suffix  = '';
  $vars['fields']['nothing']->label_html = '';

But it's like I'm defining a totally new field instead of assigning a value to the existing one

1 Answer 1

1

You are probably not accessing the fields array correctly, and creating your own additional renderable array within $vars.

Install the Devel module if you haven't already and put

dpm($vars);

at the top of your function. That will allow you to view the structure of the object on the screen (make sure you're logged in as user 1).

1
  • The problem was that the field was inside a field group so it couldn't be accessed directly. I had to put it outside and It solved the problem. Commented Feb 4, 2016 at 11:56

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.