class ConfigurationUpdateGenerator in Update helper 8
Same name in this branch
- 8 src/Generator/ConfigurationUpdateGenerator.php \Drupal\update_helper\Generator\ConfigurationUpdateGenerator
- 8 modules/update_helper_checklist/src/Generator/ConfigurationUpdateGenerator.php \Drupal\update_helper_checklist\Generator\ConfigurationUpdateGenerator
Configuration update generator for generate:configuration:update command.
@package Drupal\update_helper\Generator
Hierarchy
- class \Drupal\update_helper\Generator\ConfigurationUpdateGenerator extends \Drupal\Console\Core\Generator\Generator
Expanded class hierarchy of ConfigurationUpdateGenerator
1 file declares its use of ConfigurationUpdateGenerator
1 string reference to 'ConfigurationUpdateGenerator'
1 service uses ConfigurationUpdateGenerator
File
- src/
Generator/ ConfigurationUpdateGenerator.php, line 15
Namespace
Drupal\update_helper\GeneratorView source
class ConfigurationUpdateGenerator extends Generator {
/**
* Drupal\update_helper\ConfigHandler definition.
*
* @var \Drupal\update_helper\ConfigHandler
*/
protected $configHandler;
/**
* Drupal\Core\Extension\ModuleHandler definition.
*
* @var \Drupal\Core\Extension\ModuleHandler
*/
protected $moduleHandler;
/**
* Configuration update generator.
*
* @param \Drupal\update_helper\ConfigHandler $config_handler
* Config handler service.
* @param \Drupal\Core\Extension\ModuleHandler $module_handler
* Module handler service.
*/
public function __construct(ConfigHandler $config_handler, ModuleHandler $module_handler) {
$this->configHandler = $config_handler;
$this->moduleHandler = $module_handler;
}
/**
* Get update hook function name.
*
* @param string $module_name
* Module name.
* @param string $update_number
* Update number.
*
* @return string
* Returns update hook function name.
*/
protected function getUpdateFunctionName($module_name, $update_number) {
return $module_name . '_update_' . $update_number;
}
/**
* Generate patch file for listed modules in module defined for command.
*
* @param string $module_name
* Module name where patch will be placed.
* @param string $update_number
* Update number that will be used.
* @param string $module_list
* Comma separated list of modules.
* @param bool $from_active
* Flag if configuration should be updated from active to Yml file configs.
*
* @return bool
* Return if patch file is generated.
*/
public function generate($module_name, $update_number, $module_list, $from_active) {
if ($module_list) {
$modules = explode(',', $module_list);
}
else {
$modules = array_filter($this->moduleHandler
->getModuleList(), function (Extension $extension) {
return $extension
->getType() == 'module';
});
$modules = array_keys($modules);
}
// Get patch data and save it into file.
$patch_data = $this->configHandler
->generatePatchFile($modules, $from_active);
if (!empty($patch_data)) {
$patch_file_path = $this->configHandler
->getPatchFile($module_name, $this
->getUpdateFunctionName($module_name, $update_number), TRUE);
if (file_put_contents($patch_file_path, $patch_data)) {
$this->fileQueue
->addFile($patch_file_path);
$new_code_line = count(file($patch_file_path));
$this->countCodeLines
->addCountCodeLines($new_code_line);
return TRUE;
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurationUpdateGenerator:: |
protected | property | Drupal\update_helper\ConfigHandler definition. | |
ConfigurationUpdateGenerator:: |
protected | property | Drupal\Core\Extension\ModuleHandler definition. | |
ConfigurationUpdateGenerator:: |
public | function | Generate patch file for listed modules in module defined for command. | |
ConfigurationUpdateGenerator:: |
protected | function | Get update hook function name. | |
ConfigurationUpdateGenerator:: |
public | function | Configuration update generator. |