You are here

public function SiteAlertCommands::enable in Site Alert 8

Enable a site alert.

@command site-alert:enable

@usage drush site-alert:enable my-alert Enable the site alert with the label "my-alert".

Parameters

string $label: The label of site alert to enable.

File

src/Commands/SiteAlertCommands.php, line 202

Class

SiteAlertCommands
A Drush command file for the Site Alert module.

Namespace

Drupal\site_alert\Commands

Code

public function enable(string $label) : int {
  try {
    $count = $this->cli
      ->enable($label);
  } catch (\Exception $e) {
    $this
      ->logger()
      ->error($e
      ->getMessage());
    return self::EXIT_FAILURE;
  }
  if ($count === 0) {
    $vars = [
      '@label' => $label,
    ];
    $this
      ->logger()
      ->error((string) dt("No inactive site alerts found with the label '@label'.", $vars));
    return self::EXIT_FAILURE;
  }
  $vars = [
    '@label' => $label,
  ];
  $this
    ->logger()
    ->success((string) dt("Enabled site alert '@label'.", $vars));
  return self::EXIT_SUCCESS;
}