class ViewCloneFormController

Form controller for the Views clone form.

Hierarchy

Expanded class hierarchy of ViewCloneFormController

File

drupal/core/modules/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php, line 13
Contains \Drupal\views_ui\ViewCloneFormController.

Namespace

Drupal\views_ui
View source
class ViewCloneFormController extends ViewFormControllerBase {

  /**
   * {@inheritdoc}
   */
  public function init(array &$form_state) {
    parent::init($form_state);
    drupal_set_title(t('Clone of @label', array(
      '@label' => $this->entity
        ->label(),
    )));
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::prepareForm().
   */
  protected function prepareEntity() {

    // Do not prepare the entity while it is being added.
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::form().
   */
  public function form(array $form, array &$form_state) {
    parent::form($form, $form_state);
    $form['label'] = array(
      '#type' => 'textfield',
      '#title' => t('View name'),
      '#required' => TRUE,
      '#size' => 32,
      '#default_value' => '',
      '#maxlength' => 255,
      '#default_value' => t('Clone of @label', array(
        '@label' => $this->entity
          ->label(),
      )),
    );
    $form['id'] = array(
      '#type' => 'machine_name',
      '#maxlength' => 128,
      '#machine_name' => array(
        'exists' => 'views_get_view',
        'source' => array(
          'label',
        ),
      ),
      '#default_value' => '',
      '#description' => t('A unique machine-readable name for this View. It must only contain lowercase letters, numbers, and underscores.'),
    );
    return $form;
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::actions().
   */
  protected function actions(array $form, array &$form_state) {
    $actions['submit'] = array(
      '#value' => t('Clone'),
      '#submit' => array(
        array(
          $this,
          'submit',
        ),
      ),
    );
    return $actions;
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::form().
   */
  public function submit(array $form, array &$form_state) {
    $this->entity = parent::submit($form, $form_state);
    $this->entity
      ->setOriginalID(NULL);
    $this->entity
      ->save();

    // Redirect the user to the view admin form.
    $uri = $this->entity
      ->uri();
    $form_state['redirect'] = $uri['path'] . '/edit';
    return $this->entity;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityFormController::$entity protected property The entity being used by this form.
EntityFormController::$operation protected property The name of the current operation.
EntityFormController::actionsElement protected function Returns the action form element for the current entity form.
EntityFormController::buildEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::buildEntity(). Overrides EntityFormControllerInterface::buildEntity 2
EntityFormController::buildForm public function Form constructor. Overrides FormInterface::buildForm 1
EntityFormController::delete public function Form submission handler for the 'delete' action. 12
EntityFormController::getBaseFormID public function Returns a string identifying the base form. Overrides BaseFormIdInterface::getBaseFormID
EntityFormController::getEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getEntity(). Overrides EntityFormControllerInterface::getEntity
EntityFormController::getFormDisplay public function Returns the form display. Overrides EntityFormControllerInterface::getFormDisplay
EntityFormController::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
EntityFormController::getFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getFormLangcode(). Overrides EntityFormControllerInterface::getFormLangcode
EntityFormController::getOperation public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::getOperation(). Overrides EntityFormControllerInterface::getOperation
EntityFormController::isDefaultFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::isDefaultFormLangcode(). Overrides EntityFormControllerInterface::isDefaultFormLangcode
EntityFormController::save public function Form submission handler for the 'save' action. 20
EntityFormController::setEntity public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::setEntity(). Overrides EntityFormControllerInterface::setEntity
EntityFormController::setFormDisplay public function Sets the form display. Overrides EntityFormControllerInterface::setFormDisplay
EntityFormController::setOperation public function Sets the operation for this form.
EntityFormController::submitEntityLanguage protected function Handle possible entity language changes. 1
EntityFormController::submitForm public function Form submission handler. Overrides FormInterface::submitForm
EntityFormController::updateFormLangcode protected function Updates the form language to reflect any change to the entity language.
EntityFormController::validate public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::validate(). Overrides EntityFormControllerInterface::validate 11
EntityFormController::validateForm public function Form validation handler. Overrides FormInterface::validateForm
EntityFormController::__construct public function Constructs an EntityFormController object. 5
ViewCloneFormController::actions protected function Overrides \Drupal\Core\Entity\EntityFormController::actions(). Overrides EntityFormController::actions
ViewCloneFormController::form public function Overrides \Drupal\Core\Entity\EntityFormController::form(). Overrides EntityFormController::form
ViewCloneFormController::init public function Initialize the form state and the entity before the first form build. Overrides ViewFormControllerBase::init
ViewCloneFormController::prepareEntity protected function Overrides \Drupal\Core\Entity\EntityFormController::prepareForm(). Overrides ViewFormControllerBase::prepareEntity
ViewCloneFormController::submit public function Overrides \Drupal\Core\Entity\EntityFormController::form(). Overrides EntityFormController::submit
ViewFormControllerBase::$displayID protected property The name of the display used by the form.
ViewFormControllerBase::getAdminCSS public static function Creates an array of Views admin CSS for adding or attaching.
ViewFormControllerBase::getDisplayLabel public function Placeholder function for overriding $display['display_title'].
ViewFormControllerBase::getDisplayTabs public function Adds tabs for navigating across Displays when editing a View.
ViewFormControllerBase::isDefaultDisplayShown public function Controls whether or not the default display should have its own tab on edit.