0

Want to use hook_views_pre_render() to modify a field in view based upon data in another field. Starting with this code:

function sbn_views_pre_render(ViewExecutable $view) {
  drupal_set_message($view->id());
    foreach ($view->result as $key => $value) {
    // How do I select fields I need?
    }
}

What I don't know how to do is select the fields I want to work with from the $view object.

Some of the things I've tried so far:

kint($value->_entity->get('id')->value);

drupal_set_message($value->_object->get('id')->value);

drupal_set_message($value->get('id')->get(0));

drupal_set_message($value->get('parent_id')->getValue()['0']['value']);

Can someone tell me, or point me to documentation which will explain?

Thanks!

0

Found the answer:

// https://drupal.stackexchange.com/questions/272495/how-to-get-views-field-names-values-for-hook-views-pre-render
foreach ($view->result as $key => $value) {
  //- Get parent_id value 
  $parent_id_value =  $value->_entity->parent_id->getValue()[0]['value'];
  //- Get parent_type value
  $parent_type_value =  $value->_entity->parent_type->getValue()[0]['value'];
  drupal_set_message($parent_id_value .' | '.$parent_type_value);
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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