class ViewCloneFormController

Form controller for the Views clone form.

Hierarchy

Expanded class hierarchy of ViewCloneFormController

File

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

Namespace

Drupal\views_ui
View source
class ViewCloneFormController extends ViewFormControllerBase {

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

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

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::form().
   */
  public function form(array $form, array &$form_state, EntityInterface $entity) {
    parent::form($form, $form_state, $entity);
    $form['human_name'] = array(
      '#type' => 'textfield',
      '#title' => t('View name'),
      '#required' => TRUE,
      '#size' => 32,
      '#default_value' => '',
      '#maxlength' => 255,
      '#default_value' => t('Clone of @human_name', array(
        '@human_name' => $entity
          ->getHumanName(),
      )),
    );
    $form['name'] = array(
      '#type' => 'machine_name',
      '#maxlength' => 128,
      '#machine_name' => array(
        'exists' => 'views_get_view',
        'source' => array(
          'human_name',
        ),
      ),
      '#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) {
    $entity = parent::submit($form, $form_state);
    $entity
      ->setOriginalID(NULL);
    $entity
      ->save();

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

}

Members

Namesort descending Modifiers Type Description Overrides
EntityFormController::$operation protected property The name of the current operation.
EntityFormController::actionsElement protected function Returns the action form element for the current entity form. 1
EntityFormController::build public function Implements Drupal\Core\Entity\EntityFormControllerInterface::build(). Overrides EntityFormControllerInterface::build
EntityFormController::buildEntity public function Implements Drupal\Core\Entity\EntityFormControllerInterface::buildEntity(). Overrides EntityFormControllerInterface::buildEntity 1
EntityFormController::delete public function Form submission handler for the 'delete' action. 5
EntityFormController::getEntity public function Implements Drupal\Core\Entity\EntityFormControllerInterface::getEntity(). Overrides EntityFormControllerInterface::getEntity 1
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::init protected function Initialize the form state and the entity before the first form build.
EntityFormController::isDefaultFormLangcode public function Implements EntityFormControllerInterface::isDefaultFormLangcode(). Overrides EntityFormControllerInterface::isDefaultFormLangcode
EntityFormController::save public function Form submission handler for the 'save' action. 11
EntityFormController::setEntity public function Implements Drupal\Core\Entity\EntityFormControllerInterface::setEntity(). Overrides EntityFormControllerInterface::setEntity 1
EntityFormController::submitEntityLanguage protected function Handle possible entity language changes.
EntityFormController::validate public function Implements Drupal\Core\Entity\EntityFormControllerInterface::validate(). Overrides EntityFormControllerInterface::validate 10
EntityFormController::__construct public function Constructs an EntityFormController object.
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::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::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.