ShortcutSetDeleteForm.php in Drupal 9
File
core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php
View source
<?php
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;
class ShortcutSetDeleteForm extends EntityDeleteForm {
protected $database;
protected $storage;
public function __construct(Connection $database, ShortcutSetStorageInterface $storage) {
$this->database = $database;
$this->storage = $storage;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('entity_type.manager')
->getStorage('shortcut_set'));
}
public function buildForm(array $form, FormStateInterface $form_state) {
$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>';
}
if ($this->moduleHandler
->getImplementations('shortcut_default_set')) {
$info .= '<p>' . $this
->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'] = [
'#markup' => $info,
];
return parent::buildForm($form, $form_state);
}
}