public function InfoToYAML::convert in Drupal 7 to 8/9 Module Upgrader 8
Performs required conversions.
Parameters
TargetInterface $target: The target module to convert.
Overrides ConverterInterface::convert
File
- src/
Plugin/ DMU/ Converter/ InfoToYAML.php, line 20
Class
- InfoToYAML
- Plugin annotation @Converter( id = "info", description = @Translation("Converts Drupal 7 info files to Drupal 8.") )
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\ConverterCode
public function convert(TargetInterface $target) {
$info_file = $target
->getPath('.info');
$info = self::parseInfo($info_file);
$info['core'] = '8.x';
$info['type'] = 'module';
if (isset($info['dependencies'])) {
// array_values() is called in order to reindex the array. Issue #2340207.
$info['dependencies'] = array_values(array_diff($info['dependencies'], [
'ctools',
'list',
]));
}
// Getting list of core modules.
$listing = new ExtensionDiscovery(\Drupal::root());
$modules = $listing
->scan('module');
// Initialize variable to store depenencies in latest format.
$dependencies = [];
foreach ($info['dependencies'] ?? [] as $module_name) {
// When the module is a core module then use dependency as drupal:{module_name}.
if (!empty($modules[$module_name])) {
$dependencies[$module_name] = 'drupal:' . $module_name;
}
else {
$dependencies[$module_name] = $module_name . ':' . $module_name;
}
}
// Setting up dependencies in drupal standard format.
$info['dependencies'] = $dependencies;
unset($info['files'], $info['configure'], $info['datestamp'], $info['version'], $info['project']);
$this
->writeInfo($target, 'info', $info);
}