function drush_modules_weight_mw_reorder in Modules weight 8
Same name and namespace in other branches
- 8.2 modules_weight.drush.inc \drush_modules_weight_mw_reorder()
- 7 modules_weight.drush.inc \drush_modules_weight_mw_reorder()
Callback for the mw-reorder command.
File
- ./modules_weight.drush.inc, line 197 
- Drush commands related to the Modules weight module.
Code
function drush_modules_weight_mw_reorder() {
  $args = func_get_args();
  if (count($args) == 2) {
    // Getting the --minus option.
    $minus = drush_get_option('minus');
    // Applying the minus option.
    $weight = $minus ? -1 * $args[1] : $args[1];
    // Setting the new weight.
    module_set_weight($args[0], $weight);
    // Printing the message.
    $message = dt('The module weight for @module_name was updated to @weight.', [
      '@module_name' => $args[0],
      '@weight' => $weight,
    ]);
    drush_log($message, 'success');
  }
  else {
    // Searching for the module weigth.
    // Getting the list of installed modules from the config.
    $installed_modules = \Drupal::service('config.factory')
      ->get('core.extension')
      ->get('module') ?: [];
    // Getting the module weight.
    $weight = $installed_modules[$args[0]];
    // Getting the module name.
    $module_name = \Drupal::service('extension.list.module')
      ->getName($args[0]);
    // Creating the array with the sustitution values.
    $values = [
      '@module_name' => $module_name,
      '@machine_name' => $args[0],
      '@weight' => $weight,
    ];
    $message = dt('The weight of the @module_name [@machine_name] module is: @weight', $values);
    drush_print($message);
  }
}