How to disable views pager programatically in certain cases I have a paragraph which shows a view. The editor may set some options as argument filters, sort and show/hide pager. "Normal" fields are used to collect these options and template_preprocess_paragraph__PARAGRAPH_TYPE actually builds the view. The filtering works well, but I am not able to get rid of the pager if the editor desires to disable it while limiting the amount of items shown at the same time ($view-&gt;setItemsPerPage(0); is not an option here). Here is some simplified code from mytheme.theme:

function mytheme_preprocess_paragraph__content_list(&amp;$variables) {
  $view = Views::getView('content_list');
  if (!$view) {
    return;
  }

  // Simulate user input:
  $order = 'DESC';
  $disable_pager = TRUE;
  $items_per_page = 12;
  $filter_args = [1,2,3,4];


  $display_id = 'embed_content_list_title';
  $view-&gt;setDisplay($display_id);
  $view-&gt;setHandlerOption($display_id, 'sort', 'title', 'order', $order);

  if ($disable_pager) {
    $display = $view-&gt;getDisplay();
    $pager = [
      'type' =&gt; 'none',
      'options' =&gt; [
        'offset' =&gt; 0,
        'items_per_page' =&gt; 50,
      ],
    ];
    // This doesn't work:
    $display-&gt;setOption('pager', $pager);
    $display-&gt;setOverride('pager', $pager);
    // This neither works:
    $view-&gt;display_handler-&gt;setOption('pager', $pager);
    $view-&gt;display_handler-&gt;setOverride('pager', $pager);
    // I also had no luck with:
    $view-&gt;pager = NULL;

    $view-&gt;setItemsPerPage($items_per_page);
  }

  $view-&gt;execute();
  $variables['content']['content_list'] = $view-&gt;buildRenderable($display_id, [$filter_args]);
}


How can the pager be disabled in above code? A workaround might be using different displays, one with pager enabled and another with pager disabled. But I would prefer to solve it with just one display (as I already have multiple displays and would have to build both versions for each display).
Piggybacking off How to set views pager item size programmatically? and looking at PagerPluginBase.

To change values

if ($disable_pager == FALSE) {
  $view-&gt;setOffset(0);
  $view-&gt;setItemsPerPage($items_per_page);
}




Now to answer your question 


  How can the pager be disabled in above code?


You can disable it by setting items per page to zero.

$view-&gt;setItemsPerPage(0);


If you want to limit the amount of items without pager, all you have to do is unset it. 

   $view = Views::getView('content_list');
   $display_id = 'embed_content_list';
   $view-&gt;setDisplay($display_id);
   $view-&gt;setItemsPerPage(12);
   $view-&gt;execute();
   unset($view-&gt;pager); // must put this unset after the $view-&gt;execute();
   $variables['content']['content_list'] = $view-&gt;buildRenderable($display_id, [$filter_args]);