c383627b878ccd9b108722df55ed6472baea9f73
[yaffs-website] / web / core / modules / shortcut / src / Form / ShortcutSetDeleteForm.php
1 <?php
2
3 namespace Drupal\shortcut\Form;
4
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;
10
11 /**
12  * Builds the shortcut set deletion form.
13  */
14 class ShortcutSetDeleteForm extends EntityDeleteForm {
15
16   /**
17    * The database connection.
18    *
19    * @var \Drupal\Core\Database\Connection
20    */
21   protected $database;
22
23   /**
24    * The shortcut storage.
25    *
26    * @var \Drupal\shortcut\ShortcutSetStorageInterface
27    */
28   protected $storage;
29
30   /**
31    * Constructs a ShortcutSetDeleteForm object.
32    */
33   public function __construct(Connection $database, ShortcutSetStorageInterface $storage) {
34     $this->database = $database;
35     $this->storage = $storage;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public static function create(ContainerInterface $container) {
42     return new static(
43       $container->get('database'),
44       $container->get('entity.manager')->getStorage('shortcut_set')
45     );
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function buildForm(array $form, FormStateInterface $form_state) {
52     // Find out how many users are directly assigned to this shortcut set, and
53     // make a message.
54     $number = $this->storage->countAssignedUsers($this->entity);
55     $info = '';
56     if ($number) {
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>';
60     }
61
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>';
66     }
67
68     $form['info'] = [
69       '#markup' => $info,
70     ];
71
72     return parent::buildForm($form, $form_state);
73   }
74
75 }