Skip to content
ViewDuplicateForm.php 2.03 KiB
Newer Older
 * Contains \Drupal\views_ui\ViewDuplicateForm.
 * Form controller for the Views duplicate form.
class ViewDuplicateForm extends ViewFormBase {
  protected function prepareEntity() {
    // Do not prepare the entity while it is being added.
  }

  /**
  public function form(array $form, FormStateInterface $form_state) {
    parent::form($form, $form_state);
    $form['#title'] = $this->t('Duplicate of @label', array('@label' => $this->entity->label()));
      '#title' => $this->t('View name'),
      '#required' => TRUE,
      '#size' => 32,
      '#maxlength' => 255,
      '#default_value' => $this->t('Duplicate of @label', array('@label' => $this->entity->label())),
      '#type' => 'machine_name',
      '#maxlength' => 128,
      '#machine_name' => array(
        'exists' => '\Drupal\views\Views::getView',
      '#description' => $this->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'),
  protected function actions(array $form, FormStateInterface $form_state) {
      '#value' => $this->t('Duplicate'),
      '#submit' => array(
        array($this, 'submit'),
      ),
    );
    return $actions;
  }

  /**
  public function submit(array $form, FormStateInterface $form_state) {
    $original = parent::submit($form, $form_state);
    $this->entity = $original->createDuplicate();
    $this->entity->set('id', $form_state['values']['id']);
    $this->entity->save();
    $form_state->setRedirectUrl($this->entity->urlInfo('edit-form'));
    return $this->entity;