Interim commit.
[yaffs-website] / web / modules / contrib / bootstrap_layouts / src / BootstrapLayoutsUninstallValidator.php
1 <?php
2
3 namespace Drupal\bootstrap_layouts;
4
5 use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
6 use Drupal\Core\StringTranslation\StringTranslationTrait;
7
8 /**
9  * Class BootstrapLayoutsUninstallValidator
10  */
11 class BootstrapLayoutsUninstallValidator implements ModuleUninstallValidatorInterface {
12
13   use StringTranslationTrait;
14
15   /**
16    * The BootstrapLayouts manager.
17    *
18    * @var \Drupal\bootstrap_layouts\BootstrapLayoutsManager
19    */
20   protected $manager;
21
22   /**
23    * Constructs a new ContentUninstallValidator.
24    *
25    * @param \Drupal\bootstrap_layouts\BootstrapLayoutsManager $manager
26    *   The BootstrapLayouts manager.
27    */
28   public function __construct(BootstrapLayoutsManager $manager) {
29     $this->manager = $manager;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function validate($module) {
36     $reasons = [];
37
38     if ($module === 'bootstrap_layouts') {
39       $layouts = [];
40       foreach ($this->manager->getHandlers() as $handler) {
41         foreach ($handler->loadInstances() as $storage_id => $layout) {
42           if ($layout->isBootstrapLayout()) {
43             $layouts[$layout->getId()][] = $handler->getPluginId() . ':' . $storage_id;
44           }
45         }
46       }
47       ksort($layouts);
48       foreach ($layouts as $layout_id => $storage_ids) {
49         sort($storage_ids, SORT_NATURAL);
50         $reasons[] = $this->t('Using layout: @layout_id (@storage_ids)', [
51           '@layout_id' => $layout_id,
52           '@storage_ids' => implode(', ', $storage_ids),
53         ]);
54       }
55     }
56
57     return $reasons;
58   }
59
60 }