RequiredModuleUninstallValidator.php in Drupal 10
File
core/lib/Drupal/Core/Extension/RequiredModuleUninstallValidator.php
View source
<?php
namespace Drupal\Core\Extension;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
class RequiredModuleUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
protected $moduleExtensionList;
public function __construct(TranslationInterface $string_translation, ModuleExtensionList $extension_list_module) {
$this->stringTranslation = $string_translation;
$this->moduleExtensionList = $extension_list_module;
}
public function validate($module) {
$reasons = [];
$module_info = $this
->getModuleInfoByModule($module);
if (!empty($module_info['required'])) {
$reasons[] = $this
->t('The @module module is required', [
'@module' => $module_info['name'],
]);
}
return $reasons;
}
protected function getModuleInfoByModule($module) {
if ($this->moduleExtensionList
->exists($module)) {
return $this->moduleExtensionList
->get($module)->info;
}
return [];
}
}