
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()).