protected function InstallProfile::checkEnabledProfileExtensions in Helper 8
Check for any enabled extensions that reside inside the current profile.
Parameters
string $profile: The new desired profile.
string $type: The extension type. Possible values are module or theme.
Throws
\Drupal\Core\Installer\Exception\InstallerException If there are extensions that enabled in the currnet profile that do not also reside in the new profile.
1 call to InstallProfile::checkEnabledProfileExtensions()
- InstallProfile::validateProfile in src/
InstallProfile.php - Validates a profile and checks its various requirements.
File
- src/
InstallProfile.php, line 253
Class
- InstallProfile
- Helpers related to working with install profiles.
Namespace
Drupal\helperCode
protected function checkEnabledProfileExtensions($profile, $type) {
$current_profile = \Drupal::installProfile();
$current_profile_path = $this->profileList
->getPath($current_profile);
$new_profile_path = $this->profileList
->getPath($profile);
/** @var \Drupal\Core\Extension\ExtensionList $extensionList */
$extensionList = \Drupal::service('extension.list.' . $type);
$extensions = array_keys($extensionList
->getAllInstalledInfo());
$missing_extensions = [];
foreach ($extensions as $extension) {
// Skip the current profile (which also acts as a module) since it is not
// relevant.
if ($type === 'module' && $extension === $current_profile) {
continue;
}
// If the extension lives inside the current profile but cannot be found
// in the new profile, then add it to the list.
// @todo Convert this to use ExtensionDiscovery using the new profile path like drupal_check_profile() does.
if (strpos($extensionList
->getPath($extension), $current_profile_path) !== FALSE && !is_dir($new_profile_path . '/' . $type . '/' . $extension)) {
$missing_extensions[] = $extension;
}
}
// Throw an exception if there will be any missing extensions.
if (!empty($missing_extensions)) {
sort($missing_extensions);
throw new InstallerException("The following {$type}s are located inside the current {$current_profile} profile and may not be available when switching to the {$profile} profile: " . implode(', ', $missing_extensions) . ".");
}
}