Newer
Older
catch
committed
<?php
/**
* @file
* Contains \Drupal\views_ui\ViewDuplicateForm.
catch
committed
*/
namespace Drupal\views_ui;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
catch
committed
/**
* Form controller for the Views duplicate form.
catch
committed
*/
class ViewDuplicateForm extends ViewFormBase {
catch
committed
/**
* {@inheritdoc}
catch
committed
*/
protected function prepareEntity() {
catch
committed
// Do not prepare the entity while it is being added.
}
/**
* {@inheritdoc}
catch
committed
*/
Dries Buytaert
committed
public function form(array $form, FormStateInterface $form_state) {
parent::form($form, $form_state);
catch
committed
$form['#title'] = $this->t('Duplicate of @label', array('@label' => $this->entity->label()));
Angie Byron
committed
Angie Byron
committed
$form['label'] = array(
catch
committed
'#type' => 'textfield',
'#title' => $this->t('View name'),
catch
committed
'#required' => TRUE,
'#size' => 32,
'#maxlength' => 255,
'#default_value' => $this->t('Duplicate of @label', array('@label' => $this->entity->label())),
catch
committed
);
Angie Byron
committed
$form['id'] = array(
catch
committed
'#type' => 'machine_name',
'#maxlength' => 128,
'#machine_name' => array(
catch
committed
'exists' => '\Drupal\views\Views::getView',
Angie Byron
committed
'source' => array('label'),
catch
committed
),
'#default_value' => '',
'#description' => $this->t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'),
catch
committed
);
return $form;
}
/**
* {@inheritdoc}
catch
committed
*/
Dries Buytaert
committed
protected function actions(array $form, FormStateInterface $form_state) {
catch
committed
$actions['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Duplicate'),
catch
committed
'#submit' => array(
array($this, 'submit'),
),
);
return $actions;
}
/**
* {@inheritdoc}
catch
committed
*/
Dries Buytaert
committed
public function submit(array $form, FormStateInterface $form_state) {
Alex Pott
committed
$original = parent::submit($form, $form_state);
$this->entity = $original->createDuplicate();
$this->entity->set('id', $form_state['values']['id']);
catch
committed
// Redirect the user to the view admin form.
Alex Pott
committed
$form_state->setRedirectUrl($this->entity->urlInfo('edit-form'));