0

I have a view which presents values of specific content type, nothing special, just a normal regular view with a table display. Later on I added to it a field from views field view module. Everythink works as expected. Now I need to hide every row which has an empty value of this views field view field?

Any ideas how can I do it?

I tried to use hook_views_pre_render but in this case I can only get an access to values of fields from parent view not from the one which comes from views field view.

Any help will be appreciated!

P.S. The question applies to Drupal 8

2 Answers 2

2

You can do it in a preprocess template function.
e.g.

/**
 * Implements template_preprocess_views_view_table()
 * @param $variables
 */
function TEMPLATE_preprocess_views_view_table(&$variables){
  /** @var ViewExecutable $view */
  $view = $variables['view'];

  //Do no alter other views
  if ($view->id() !== 'YOUR_VIEW_ID') return;

  $rows = $variables['rows'];
  foreach ($rows as $key => $row){
    if (empty($row['columns']['VIEWS_FIELD_VIEW_FIELD_NAME']['content'])){
      unset($variables['rows'][$key]);
    }
  }
}

Replace
TEMPLATE with your module name or theme name. YOUR_VIEW_ID with your view id VIEWS_FIELD_VIEW_FIELD_NAME with the name of your field

Hope that helps

1

Are you passing argument to the view embed? If true, you should apply the hide field if that argument is empty, so you don't need to control the row on the new view.

Your Answer

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

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