-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #474684 by bnjmnm, dawehner, tedbow, pfrenssen, JohnAlbin, adem…
…arco, kalpaitch, vdacosta@voidtek.com, rensingh99, markcarver, jungle, jhedstrom, RobLoach, almaudoh, kevineinarsson, shaal, dpagini, thedavidmeister, sreynen, Snugug, Miguel.kode, kamkejj, alexpott, Pol, sun, Wim Leers, lauriii, tim.plunkett, eaton: Allow themes to declare dependencies on modules
- Loading branch information
catch
committed
Mar 19, 2020
1 parent
353773b
commit 6e9d3de
Showing
31 changed files
with
1,119 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
lib/Drupal/Core/Extension/ModuleRequiredByThemesUninstallValidator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
namespace Drupal\Core\Extension; | ||
|
||
use Drupal\Core\StringTranslation\StringTranslationTrait; | ||
use Drupal\Core\StringTranslation\TranslationInterface; | ||
|
||
/** | ||
* Ensures modules cannot be uninstalled if enabled themes depend on them. | ||
*/ | ||
class ModuleRequiredByThemesUninstallValidator implements ModuleUninstallValidatorInterface { | ||
|
||
use StringTranslationTrait; | ||
|
||
/** | ||
* The module extension list. | ||
* | ||
* @var \Drupal\Core\Extension\ModuleExtensionList | ||
*/ | ||
protected $moduleExtensionList; | ||
|
||
/** | ||
* The theme extension list. | ||
* | ||
* @var \Drupal\Core\Extension\ThemeExtensionList | ||
*/ | ||
protected $themeExtensionList; | ||
|
||
/** | ||
* Constructs a new ModuleRequiredByThemesUninstallValidator. | ||
* | ||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation | ||
* The string translation service. | ||
* @param \Drupal\Core\Extension\ModuleExtensionList $extension_list_module | ||
* The module extension list. | ||
* @param \Drupal\Core\Extension\ThemeExtensionList $extension_list_theme | ||
* The theme extension list. | ||
*/ | ||
public function __construct(TranslationInterface $string_translation, ModuleExtensionList $extension_list_module, ThemeExtensionList $extension_list_theme) { | ||
$this->stringTranslation = $string_translation; | ||
$this->moduleExtensionList = $extension_list_module; | ||
$this->themeExtensionList = $extension_list_theme; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate($module) { | ||
$reasons = []; | ||
|
||
$themes_depending_on_module = $this->getThemesDependingOnModule($module); | ||
if (!empty($themes_depending_on_module)) { | ||
$module_name = $this->moduleExtensionList->get($module)->info['name']; | ||
$theme_names = implode(', ', $themes_depending_on_module); | ||
$reasons[] = $this->formatPlural(count($themes_depending_on_module), | ||
'Required by the theme: @theme_names', | ||
'Required by the themes: @theme_names', | ||
['@module_name' => $module_name, '@theme_names' => $theme_names]); | ||
} | ||
|
||
return $reasons; | ||
} | ||
|
||
/** | ||
* Returns themes that depend on a module. | ||
* | ||
* @param string $module | ||
* The module machine name. | ||
* | ||
* @return string[] | ||
* An array of the names of themes that depend on $module. | ||
*/ | ||
protected function getThemesDependingOnModule($module) { | ||
$installed_themes = $this->themeExtensionList->getAllInstalledInfo(); | ||
$themes_depending_on_module = array_map(function ($theme) use ($module) { | ||
if (in_array($module, $theme['dependencies'])) { | ||
return $theme['name']; | ||
} | ||
}, $installed_themes); | ||
|
||
return array_filter($themes_depending_on_module); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.