class ShortcutFormController

Form controller for the shortcut set entity edit forms.

Hierarchy

Expanded class hierarchy of ShortcutFormController

File

drupal/core/modules/shortcut/lib/Drupal/shortcut/ShortcutFormController.php, line 15
Contains \Drupal\shortcut\ShortcutFormController.

Namespace

Drupal\shortcut
View source
class ShortcutFormController extends EntityFormController {

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::form().
   */
  public function form(array $form, array &$form_state) {
    $form = parent::form($form, $form_state);
    $entity = $this->entity;
    $form['label'] = array(
      '#type' => 'textfield',
      '#title' => t('Set name'),
      '#description' => t('The new set is created by copying items from your default shortcut set.'),
      '#required' => TRUE,
      '#default_value' => $entity
        ->label(),
    );
    $form['id'] = array(
      '#type' => 'machine_name',
      '#machine_name' => array(
        'exists' => 'shortcut_set_load',
        'source' => array(
          'label',
        ),
        'replace_pattern' => '[^a-z0-9-]+',
        'replace' => '-',
      ),
      '#default_value' => $entity
        ->id(),
      '#disabled' => !$entity
        ->isNew(),
      // This id could be used for menu name.
      '#maxlength' => 23,
    );
    $form['actions']['submit']['#value'] = t('Create new set');
    return $form;
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::actions().
   */
  protected function actions(array $form, array &$form_state) {

    // Disable delete of default shortcut set.
    $actions = parent::actions($form, $form_state);
    $actions['delete']['#access'] = $this->entity
      ->access('delete');
    return $actions;
  }

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

    // Check to prevent a duplicate title.
    if ($form_state['values']['label'] != $entity
      ->label() && shortcut_set_title_exists($form_state['values']['label'])) {
      form_set_error('label', t('The shortcut set %name already exists. Choose another name.', array(
        '%name' => $form_state['values']['label'],
      )));
    }
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::save().
   */
  public function save(array $form, array &$form_state) {
    $entity = $this->entity;
    $is_new = !$entity
      ->getOriginalID();
    $entity
      ->save();
    if ($is_new) {
      drupal_set_message(t('The %set_name shortcut set has been created. You can edit it from this page.', array(
        '%set_name' => $entity
          ->label(),
      )));
    }
    else {
      drupal_set_message(t('Updated set name to %set-name.', array(
        '%set-name' => $entity
          ->label(),
      )));
    }
    $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $entity
      ->id();
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityFormController::delete().
   */
  public function delete(array $form, array &$form_state) {
    $entity = $this->entity;
    $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $entity
      ->id() . '/delete';
  }

}

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::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::init protected function Initialize the form state and the entity before the first form build. 1
EntityFormController::isDefaultFormLangcode public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::isDefaultFormLangcode(). Overrides EntityFormControllerInterface::isDefaultFormLangcode
EntityFormController::prepareEntity protected function Prepares the entity object before the form is built first. 3
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::submit public function Implements \Drupal\Core\Entity\EntityFormControllerInterface::submit(). Overrides EntityFormControllerInterface::submit 13
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::validateForm public function Form validation handler. Overrides FormInterface::validateForm
EntityFormController::__construct public function Constructs an EntityFormController object. 5
ShortcutFormController::actions protected function Overrides \Drupal\Core\Entity\EntityFormController::actions(). Overrides EntityFormController::actions
ShortcutFormController::delete public function Overrides \Drupal\Core\Entity\EntityFormController::delete(). Overrides EntityFormController::delete
ShortcutFormController::form public function Overrides \Drupal\Core\Entity\EntityFormController::form(). Overrides EntityFormController::form
ShortcutFormController::save public function Overrides \Drupal\Core\Entity\EntityFormController::save(). Overrides EntityFormController::save
ShortcutFormController::validate public function Overrides \Drupal\Core\Entity\EntityFormController::validate(). Overrides EntityFormController::validate