"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/shortcut/src/Form/ShortcutSetDeleteForm.php" (26 Nov 2020, 2122 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ShortcutSetDeleteForm.php" see the Fossies "Dox" file reference documentation.

    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  * @internal
   15  */
   16 class ShortcutSetDeleteForm extends EntityDeleteForm {
   17 
   18   /**
   19    * The database connection.
   20    *
   21    * @var \Drupal\Core\Database\Connection
   22    */
   23   protected $database;
   24 
   25   /**
   26    * The shortcut storage.
   27    *
   28    * @var \Drupal\shortcut\ShortcutSetStorageInterface
   29    */
   30   protected $storage;
   31 
   32   /**
   33    * Constructs a ShortcutSetDeleteForm object.
   34    */
   35   public function __construct(Connection $database, ShortcutSetStorageInterface $storage) {
   36     $this->database = $database;
   37     $this->storage = $storage;
   38   }
   39 
   40   /**
   41    * {@inheritdoc}
   42    */
   43   public static function create(ContainerInterface $container) {
   44     return new static(
   45       $container->get('database'),
   46       $container->get('entity_type.manager')->getStorage('shortcut_set')
   47     );
   48   }
   49 
   50   /**
   51    * {@inheritdoc}
   52    */
   53   public function buildForm(array $form, FormStateInterface $form_state) {
   54     // Find out how many users are directly assigned to this shortcut set, and
   55     // make a message.
   56     $number = $this->storage->countAssignedUsers($this->entity);
   57     $info = '';
   58     if ($number) {
   59       $info .= '<p>' . $this->formatPlural($number,
   60         '1 user has chosen or been assigned to this shortcut set.',
   61         '@count users have chosen or been assigned to this shortcut set.') . '</p>';
   62     }
   63 
   64     // Also, if a module implements hook_shortcut_default_set(), it's possible
   65     // that this set is being used as a default set. Add a message about that too.
   66     if ($this->moduleHandler->getImplementations('shortcut_default_set')) {
   67       $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>';
   68     }
   69 
   70     $form['info'] = [
   71       '#markup' => $info,
   72     ];
   73 
   74     return parent::buildForm($form, $form_state);
   75   }
   76 
   77 }