You are here

function drush_modules_weight_mw_show_system_modules in Modules weight 8.2

Same name and namespace in other branches
  1. 8 modules_weight.drush.inc \drush_modules_weight_mw_show_system_modules()
  2. 7 modules_weight.drush.inc \drush_modules_weight_mw_show_system_modules()

Callback for the mw-show-system-modules command.

File

./modules_weight.drush.inc, line 124
Drush commands related to the Modules weight module.

Code

function drush_modules_weight_mw_show_system_modules() {
  $args = func_get_args();

  // Getting an editable config because we will get and set a value.
  $config = \Drupal::service('config.factory')
    ->getEditable('modules_weight.settings');

  // Getting the values from the config.
  $show_system_modules = $config
    ->get('show_system_modules');

  // Giving colors to the messages.
  $activated = sprintf(MODULES_WEIGHT_GREEN_OUTPUT, dt('Activated'));
  $disabled = sprintf(MODULES_WEIGHT_RED_OUTPUT, dt('Disabled'));
  if (isset($args[0])) {
    list($value, $status) = $args[0] == 'on' ? [
      1,
      strtolower($activated),
    ] : [
      0,
      strtolower($disabled),
    ];

    // Is already configured?
    if ($show_system_modules == $value) {

      // If is configured stop the command execution with a warning message.
      $message = dt('The core modules reorder option is already @status.', [
        '@status' => $status,
      ]);
      drush_log($message, 'warning');

      // Returning here to stop the function execution.
      return;
    }

    // Saving the values in the config.
    $config
      ->set('show_system_modules', $value);
    $config
      ->save();
    $message = dt('You have @status the core modules reorder option.', [
      '@status' => $status,
    ]);
    drush_log($message, 'success');
  }
  else {
    $status = $show_system_modules ? $activated : $disabled;
    $message = dt('The core modules reorder option is: @status', [
      '@status' => $status,
    ]);
    drush_print($message);
  }
}