How can I programmatically change the view mode? In Drupal 7 I did something like:

  function mymodule_views_pre_render(&amp;$view) {
    //dpm($view);
    if ($view-&gt;name == 'services') {
      $view-&gt;style_plugin-&gt;row_plugin-&gt;options['view_mode'] = variable_get('services_teaser');
    }
    else if ($view-&gt;name == 'portfolio') {
      $view-&gt;style_plugin-&gt;row_plugin-&gt;options['view_mode'] = variable_get('portfolio_teaser');
    }
  }


I don't know how to set the view mode on the fly, in Drupal 8. The idea is to be able to select the view mode for the view from a configuration form, instead of doing it from the view form.

How do I achieve this?
You can select VIew Mode as:

function YOUR_MODULE_entity_view_mode_alter(&amp;$view_mode, Drupal\Core\Entity\EntityInterface $entity, $context) {
  if ($entity-&gt;getEntityTypeId() == 'taxonomy_term' &amp;&amp; $entity-&gt;bundle() == 'tag' &amp;&amp; $view_mode == 'full') {
    $view_mode = 'CUSTOM VIEW MODE';
  }
}