How to get the views field value and make a condition base on that field. Let say may views field is ‘field_state’
Example below:
function my_module_views_pre_render(ViewExecutable $view) { //current user id $user_id = Drupal::currentUser()->id(); //load user data $user = DrupaluserEntityUser::load($user_id); // Get user state $state = $user->get('field_state')->getValue()[0]['value']; if ($state == Views field_state value) { $view->field['field_state']->options['exclude'] = TRUE; // exclude field for only this result ??? } else{ $view->field['field_state']->options['exclude'] = FALSE; // include field for only this result ??? } }
Is it possible on views pre-render or I need to use the different hook?