public function ViewEditFormController::submitDisplayDuplicate

Submit handler to duplicate a display for a view.

File

drupal/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php, line 730
Contains Drupal\views_ui\ViewEditFormController.

Class

ViewEditFormController
Form controller for the Views edit form.

Namespace

Drupal\views_ui

Code

public function submitDisplayDuplicate($form, &$form_state) {
  $view = $this
    ->getEntity($form_state);
  $display_id = $view->displayID;

  // Create the new display.
  $displays = $view
    ->get('display');
  $new_display_id = $view
    ->addDisplay($displays[$display_id]['display_plugin']);
  $displays[$new_display_id] = $displays[$display_id];
  $displays[$new_display_id]['id'] = $new_display_id;
  $view
    ->set('display', $displays);

  // By setting the current display the changed marker will appear on the new
  // display.
  $view
    ->get('executable')->current_display = $new_display_id;
  views_ui_cache_set($view);

  // Redirect to the new display's edit page.
  $form_state['redirect'] = 'admin/structure/views/view/' . $view
    ->get('name') . '/edit/' . $new_display_id;
}