3 namespace Drupal\shortcut\Form;
5 use Drupal\Core\Entity\EntityDeleteForm;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\shortcut\ShortcutSetStorageInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9 use Drupal\Core\Database\Connection;
12 * Builds the shortcut set deletion form.
14 class ShortcutSetDeleteForm extends EntityDeleteForm {
17 * The database connection.
19 * @var \Drupal\Core\Database\Connection
24 * The shortcut storage.
26 * @var \Drupal\shortcut\ShortcutSetStorageInterface
31 * Constructs a ShortcutSetDeleteForm object.
33 public function __construct(Connection $database, ShortcutSetStorageInterface $storage) {
34 $this->database = $database;
35 $this->storage = $storage;
41 public static function create(ContainerInterface $container) {
43 $container->get('database'),
44 $container->get('entity.manager')->getStorage('shortcut_set')
51 public function buildForm(array $form, FormStateInterface $form_state) {
52 // Find out how many users are directly assigned to this shortcut set, and
54 $number = $this->storage->countAssignedUsers($this->entity);
57 $info .= '<p>' . $this->formatPlural($number,
58 '1 user has chosen or been assigned to this shortcut set.',
59 '@count users have chosen or been assigned to this shortcut set.') . '</p>';
62 // Also, if a module implements hook_shortcut_default_set(), it's possible
63 // that this set is being used as a default set. Add a message about that too.
64 if ($this->moduleHandler->getImplementations('shortcut_default_set')) {
65 $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>';
72 return parent::buildForm($form, $form_state);