You are here

public function SiteAlertCommands::disable in Site Alert 8

Disable site alert(s).

@command site-alert:disable

@usage drush site-alert:disable Disable all site alerts. @usage drush site-alert:disable "my-alert" Disable the site alert with the label "my-alert".

Parameters

string|null $label: The label of site alert to disable. If no label is passed all site alerts will be disabled.

File

src/Commands/SiteAlertCommands.php, line 160

Class

SiteAlertCommands
A Drush command file for the Site Alert module.

Namespace

Drupal\site_alert\Commands

Code

public function disable(?string $label = NULL) : int {
  try {
    $count = $this->cli
      ->disable($label);
  } catch (\Exception $e) {
    $this
      ->logger()
      ->error($e
      ->getMessage());
    return self::EXIT_FAILURE;
  }
  if ($count === 0) {

    // If a specific alert was given and it could not be disabled, then the
    // user has given invalid input. Alert the user by returning an error.
    if (!empty($label)) {
      $vars = [
        '@label' => $label,
      ];
      $this
        ->logger()
        ->error((string) dt("No active site alerts found with the label '@label'.", $vars));
      return self::EXIT_FAILURE;
    }
    else {
      $this
        ->logger()
        ->notice('There were no site alerts to disable.');
    }
  }
  elseif (empty($label)) {
    $this
      ->logger()
      ->success('All active site alerts have been disabled.');
  }
  else {
    $vars = [
      '@label' => $label,
    ];
    $this
      ->logger()
      ->success((string) dt("Disabled site alert '@label'.", $vars));
  }
  return self::EXIT_SUCCESS;
}