function drush_modules_weight_mw_reorder_validate in Modules weight 8.2
Same name and namespace in other branches
- 8 modules_weight.drush.inc \drush_modules_weight_mw_reorder_validate()
- 7 modules_weight.drush.inc \drush_modules_weight_mw_reorder_validate()
Implements drush_hook_COMMAND_validate().
File
- ./
modules_weight.drush.inc, line 165 - Drush commands related to the Modules weight module.
Code
function drush_modules_weight_mw_reorder_validate() {
$args = func_get_args();
// Check for 1 or 2 arguments.
if (count($args) < 1 || count($args) > 2) {
return drush_set_error('MODULES_WEIGHT_INVALID_ARGUMENT', dt('This command use one or two arguments.'));
}
// Check for a valid or installed module machine name.
if (!\Drupal::service('module_handler')
->moduleExists($args[0])) {
return drush_set_error('MODULES_WEIGHT_INVALID_MODULE_NAME', dt('@module_name module machine name is invalid or is not installed.', [
'@module_name' => $args[0],
]));
}
// Check for integer number.
if (isset($args[1]) && !ctype_digit($args[1])) {
return drush_set_error('MODULES_WEIGHT_INVALID_ARGUMENT', dt('You must enter digits for the modules-weight.'));
}
// Getting the --force option.
$force = drush_get_option('force');
// Getting the module info.
$module = \Drupal::service('module_handler')
->getModule($args[0]);
$module = \Drupal::service('info_parser')
->parse($module
->getPathname());
// Getting the config to know of we should show or not the core modules.
$show_system_modules = \Drupal::service('config.factory')
->get('modules_weight.settings')
->get('show_system_modules');
// Checking if we can reorder the Core modules.
if (!$force && $module['package'] == 'Core' && !$show_system_modules) {
if (!drush_confirm(dt("You're trying to reorder a Core module but Modules Weight is not configured to allow it. Do you want to continue?"))) {
return drush_user_abort();
}
}
}