You are here

ShortcutSetDeleteForm.php in Zircon Profile 8.0

Same filename and directory in other branches
  1. 8 core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php

File

core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php
View source
<?php

/**
 * @file
 * Contains \Drupal\shortcut\Form\ShortcutSetDeleteForm.
 */
namespace Drupal\shortcut\Form;

use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\shortcut\ShortcutSetStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;

/**
 * Builds the shortcut set deletion form.
 */
class ShortcutSetDeleteForm extends EntityDeleteForm {

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

  /**
   * The shortcut storage.
   *
   * @var \Drupal\shortcut\ShortcutSetStorageInterface
   */
  protected $storage;

  /**
   * Constructs a ShortcutSetDeleteForm object.
   */
  public function __construct(Connection $database, ShortcutSetStorageInterface $storage) {
    $this->database = $database;
    $this->storage = $storage;
  }

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    // Find out how many users are directly assigned to this shortcut set, and
    // make a message.
    $number = $this->storage
      ->countAssignedUsers($this->entity);
    $info = '';
    if ($number) {
      $info .= '<p>' . $this
        ->formatPlural($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);
  }

}

Classes

Namesort descending Description
ShortcutSetDeleteForm Builds the shortcut set deletion form.