Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Extension / RequiredModuleUninstallValidator.php
1 <?php
2
3 namespace Drupal\Core\Extension;
4
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
6 use Drupal\Core\StringTranslation\TranslationInterface;
7
8 /**
9  * Ensures that required modules cannot be uninstalled.
10  */
11 class RequiredModuleUninstallValidator implements ModuleUninstallValidatorInterface {
12
13   use StringTranslationTrait;
14
15   /**
16    * Constructs a new RequiredModuleUninstallValidator.
17    *
18    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
19    *   The string translation service.
20    */
21   public function __construct(TranslationInterface $string_translation) {
22     $this->stringTranslation = $string_translation;
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public function validate($module) {
29     $reasons = [];
30     $module_info = $this->getModuleInfoByModule($module);
31     if (!empty($module_info['required'])) {
32       $reasons[] = $this->t('The @module module is required', ['@module' => $module_info['name']]);
33     }
34     return $reasons;
35   }
36
37   /**
38    * Returns the module info for a specific module.
39    *
40    * @param string $module
41    *   The name of the module.
42    *
43    * @return array
44    *   The module info, or NULL if that module does not exist.
45    */
46   protected function getModuleInfoByModule($module) {
47     $modules = system_rebuild_module_data();
48     return isset($modules[$module]->info) ? $modules[$module]->info : [];
49   }
50
51 }