function ViewEditForm::submitDisplayDuplicate

Same name in other branches
  1. 9 core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::submitDisplayDuplicate()
  2. 10 core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::submitDisplayDuplicate()
  3. 11.x core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::submitDisplayDuplicate()

Submit handler to duplicate a display for a view.

File

core/modules/views_ui/src/ViewEditForm.php, line 839

Class

ViewEditForm
Form controller for the Views edit form.

Namespace

Drupal\views_ui

Code

public function submitDisplayDuplicate($form, FormStateInterface $form_state) {
    $view = $this->entity;
    $display_id = $this->displayID;
    // Create the new display.
    $displays = $view->get('display');
    $display = $view->getExecutable()
        ->newDisplay($displays[$display_id]['display_plugin']);
    $new_display_id = $display->display['id'];
    $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->getExecutable()->current_display = $new_display_id;
    $view->cacheSet();
    // Redirect to the new display's edit page.
    $form_state->setRedirect('entity.view.edit_display_form', [
        'view' => $view->id(),
        'display_id' => $new_display_id,
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.