How to switch view before render current view? I am using Field Collection Views module which allowed to create field widget as a view.

My requirement is to allow content author to choose widget for output this field (Field Collection). I added select field to article type to choose widget from two Field Collection Views views.

Field Collection is using views_embed_view for rendering this field, so I am trying to use hook_views_pre_view to switch to different view if author choose other than default view (display formatter)

/*
 * Implements hook_views_pre_view()
 */
function wzp_gallery_views_pre_view(&amp;$view, &amp;$display_id, &amp;$args) {
    $node = menu_get_object();
    if (! $node-&gt;type == 'article') {
        return;
    }
    $field_name = FIELD_GALLERY_VIEW_FIELD_NAME;
    if (! $node-&gt;$field_name) {
        return;
    }
    $value = array_shift($node-&gt;$field_name);
    $view_info = explode('#', $value[0]['value']);
    if (! $view_info) {
        return;
    }
    $name = $view_info[0];
    $id = $view_info[1];
    if ($view-&gt;name == $name &amp;&amp; $display_id == $id) {
        return;
    }
    $display_id = $id;
    if ($view-&gt;name == $name) {
        return;
    }
    drupal_set_message('&lt;pre&gt;' . print_r($name, 1) . '&lt;/pre&gt;');
    drupal_set_message('&lt;pre&gt;' . print_r($id, 1) . '&lt;/pre&gt;');
    $view = views_get_view($name);
    $view-&gt;set_display($id);
    $view-&gt;preview = TRUE;
}


but I am end up always with default view rendered.

Code form Field Collection Views module:

/**
 * Implements hook_field_formatter_view().
 */
function field_collection_views_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];

  switch ($display['type']) {
    case 'field_collection_views_view':
      //debug($items);
      $args = '';
      $i = 1;
      foreach ($items as $delta =&gt; $item) {
        if ($i == 1) {
          $args .= $item['value'];
        }
        else {
          $args .= '+' . $item['value'];
        }
        $i++;
      }
      $view_name = isset($settings['name']) ? $settings['name'] : 'field_collection_view';
      $display_id = isset($settings['display_id']) ? $settings['display_id'] : 'default';
      $content = views_embed_view($view_name, $display_id, $args);
      $element[0] = array(
        '#markup' =&gt; $content,
      );
      if (empty($items)) {
        field_collection_field_formatter_links($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
      }
      break;
  }
  return $element;
}


Could someone give me any advice?
Answer

You can't switch view during render process but current display id.