class SetDelete

Builds the shortcut set deletion form.

Hierarchy

Expanded class hierarchy of SetDelete

1 string reference to 'SetDelete'
shortcut.routing.yml in drupal/core/modules/shortcut/shortcut.routing.yml
drupal/core/modules/shortcut/shortcut.routing.yml

File

drupal/core/modules/shortcut/lib/Drupal/shortcut/Form/SetDelete.php, line 20
Contains \Drupal\shortcut\Form\SetDelete.

Namespace

Drupal\shortcut\Form
View source
class SetDelete extends ConfirmFormBase implements ControllerInterface {

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The shortcut set being deleted.
   *
   * @var \Drupal\shortcut\Plugin\Core\Entity\Shortcut
   */
  protected $shortcut;

  /**
   * Constructs a SetDelete object.
   */
  public function __construct(Connection $database, ModuleHandlerInterface $module_handler) {
    $this->database = $database;
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('database'), $container
      ->get('module_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
    return 'shortcut_set_delete_form';
  }

  /**
   * {@inheritdoc}
   */
  protected function getQuestion() {
    return t('Are you sure you want to delete the shortcut set %title?', array(
      '%title' => $this->shortcut
        ->label(),
    ));
  }

  /**
   * {@inheritdoc}
   */
  protected function getCancelPath() {
    return 'admin/config/user-interface/shortcut/manage/' . $this->shortcut
      ->id();
  }

  /**
   * {@inheritdoc}
   */
  protected function getConfirmText() {
    return t('Delete');
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, array &$form_state, Shortcut $shortcut = NULL) {
    $this->shortcut = $shortcut;

    // Find out how many users are directly assigned to this shortcut set, and
    // make a message.
    $number = $this->database
      ->query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(
      ':name' => $this->shortcut
        ->id(),
    ))
      ->fetchField();
    $info = '';
    if ($number) {
      $info .= '<p>' . format_plural($number, '1 user has chosen or been assigned to this shortcut set.', '@count users have chosen or been assigned to this shortcut set.') . '</p>';
    }

    // Also, if a module implements hook_shortcut_default_set(), it's possible
    // that this set is being used as a default set. Add a message about that too.
    if ($this->moduleHandler
      ->getImplementations('shortcut_default_set')) {
      $info .= '<p>' . t('If you have chosen this shortcut set as the default for some or all users, they may also be affected by deleting it.') . '</p>';
    }
    $form['info'] = array(
      '#markup' => $info,
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, array &$form_state) {
    $this->shortcut
      ->delete();
    $form_state['redirect'] = 'admin/config/user-interface/shortcut';
    drupal_set_message(t('The shortcut set %title has been deleted.', array(
      '%title' => $this->shortcut
        ->label(),
    )));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfirmFormBase::getCancelText protected function Returns a caption for the link which cancels the action. 2
ConfirmFormBase::getDescription protected function Returns additional text to display as a description. 10
ConfirmFormBase::getFormName protected function Returns the internal name used to refer to the confirmation item.
ConfirmFormBase::validateForm public function Implements \Drupal\Core\Form\FormInterface::validateForm(). Overrides FormInterface::validateForm 1
SetDelete::$database protected property The database connection.
SetDelete::$moduleHandler protected property The module handler service.
SetDelete::$shortcut protected property The shortcut set being deleted.
SetDelete::buildForm public function Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides ConfirmFormBase::buildForm
SetDelete::create public static function Instantiates a new instance of this controller. Overrides ControllerInterface::create
SetDelete::getCancelPath protected function Returns the page to go to if the user cancels the action. Overrides ConfirmFormBase::getCancelPath
SetDelete::getConfirmText protected function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
SetDelete::getFormID public function Returns a unique string identifying the form. Overrides FormInterface::getFormID
SetDelete::getQuestion protected function Returns the question to ask the user. Overrides ConfirmFormBase::getQuestion
SetDelete::submitForm public function Form submission handler. Overrides FormInterface::submitForm
SetDelete::__construct public function Constructs a SetDelete object.