Problem/Motivation
Coming from #2825834: Prevent PreExistingConfigurationException by prioritizing features config.
In the following method of FeaturesManager, the undeclared variable $module is used, where apparently the intent was to use the argument-provided variable $module_name:
public function loadPackage($module_name, $any = FALSE) {
$package = $this->getPackage($module_name);
if ($any && !isset($package)) {
// See if this is a non-features module.
$module_list = $this->moduleHandler->getModuleList();
if (!empty($module_list[$module])) {
$extension = $module_list[$module];
$package = $this->initPackageFromExtension($extension);
$config = $this->listExtensionConfig($extension);
$package->setConfig($config);
$package->setStatus(FeaturesManagerInterface::STATUS_INSTALLED);
}
}
return $package;
}
As a result, the code within the control structure if (!empty($module_list[$module])) { will never be executed. The affected code is conditionally executed if the $all argument is set to TRUE.
Proposed resolution
The fact that this code segment is broken but there don't appear to be any related bug reports suggests it may no longer be needed. However, since ::loadPackage() is a public method defined in the FeaturesManagerInterface interface, we shouldn't in any case just drop the $all argument that triggers the broken segment.
Instead, we should provide a test and an accompanying fix to the variable name.
That said, we should also review all code calling ::loadPackage() with $all set to TRUE, to determine if it's still needed.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | variable_name_error_in-2828870-2.patch | 730 bytes | haza |
Comments
Comment #2
hazaThis was introduced by #2741403: Revert(Import) a feature programmatically
This part was refactored and the variable names has been changed.
This code is used by a service, allowing us to easily "revert" a feature :
\Drupal::service('features.manager')->import($module_list)The small patch is attached that only fixes the variable name.
Comment #5
nedjoIdeally we would have an accompanying test but we're currently short on maintainer time so applying this fix without one.
Thanks @Haza!