function ViewDuplicateForm::submitForm

Same name and namespace in other branches
  1. 9 core/modules/views_ui/src/ViewDuplicateForm.php \Drupal\views_ui\ViewDuplicateForm::submitForm()
  2. 8.9.x core/modules/views_ui/src/ViewDuplicateForm.php \Drupal\views_ui\ViewDuplicateForm::submitForm()
  3. 11.x core/modules/views_ui/src/ViewDuplicateForm.php \Drupal\views_ui\ViewDuplicateForm::submitForm()

Form submission handler for the 'clone' action.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: A reference to a keyed array containing the current state of the form.

Overrides EntityForm::submitForm

File

core/modules/views_ui/src/ViewDuplicateForm.php, line 103

Class

ViewDuplicateForm
Form controller for the Views duplicate form.

Namespace

Drupal\views_ui

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  // The original ID gets set to NULL when duplicating, so we need to store it
  // here.
  $original_id = $this->entity
    ->id();
  $this->entity = $this->entity
    ->createDuplicate();
  $this->entity
    ->set('label', $form_state->getValue('label'));
  $this->entity
    ->set('id', $form_state->getValue('id'));
  $this->entity
    ->save();
  $this->copyTranslations($original_id);
  // Redirect the user to the view admin form.
  $form_state->setRedirectUrl($this->entity
    ->toUrl('edit-form'));
}

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