Drupal 9 image field migration

As you know views has good pager configuration, where you can set how many items skip (offset), how many display etc.
But it has no info of minimum items to display!
For example we dont want to show the block if there are less than 5 items in results. Maybe it will break styles or somthing else.
In this case a simple condition in hook_views_post_execute will be useful :

/**
 * Implements hook_views_post_execute().
 */
function my_commerce_views_post_execute(ViewExecutable $view) {
  // Do not display block if there is less than 5 products.
  if ($view->id() == 'my_view_id'
    && $view->current_display == 'my_display_name'
    // && \Drupal::currentUser()->isAnonymous()
  ) {
    if (count($view->result) < 5) {
      $view->build_info['fail'] = TRUE;
    }
  }
} 

Also additional condition could be added to prevent showing block only for anonymous users (\Drupal::currentUser()->isAnonymous()).

Add new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed.
CAPTCHA
 ooooooooo.        .                     .    oooo                    
`888 `Y88. .o8 .o8 `888
888 .d88' .o888oo oooo ooo .o888oo 888 .oo. .ooooo oo
888ooo88P' 888 `88. .8' 888 888P"Y88b d88' `888
888`88b. 888 `88..8' 888 888 888 888 888
888 `88b. 888 . `888' 888 . 888 888 888 888
o888o o888o "888" .8' "888" o888o o888o `V8bod888
.o..P' 888.
`Y8P' 8P'
"
Enter the code depicted in ASCII art style.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.