You are here

public function SiteAlertCommands::create in Site Alert 8

Create a site alert.

@command site-alert:create

@option start Optional time when the site alert should appear. Can be in ISO 8601 format ("2020-10-22T14:30:00-05:00") or in a human readable format like "October 22, 2020" or "Saturday 12:30". @option end Optional time when the site alert should disappear. Can be in ISO 8601 format ("2020-10-22T14:30:00-05:00") or in a human readable format like "+6 hours" or "midnight". @option severity Optional severity of the site alert [low, medium (default), high]. @option active Marks the site alert as active.

@usage drush site-alert:create "label" "Message" Create a site-alert with the label and message with medium severity. The alert will be immediately visible and will remain so until manually disabled or deleted. @usage drush site-alert:create "label name" "message" --severity=high --no-active. Create a site-alert with the label and message with high severity. The alert is inactive and will not be visible until activated. @usage drush site-alert:create "label name" "message" --start=2022-10-15T15:00:00 --end=2022-10-15T17:00:00 Create a site alert with the label and message that will be displayed between the start and end dates provided. @usage drush site-alert:create "label name" "message" --start=13:45 --end="tomorrow 13:45" Create a site alert with the label and message that will be displayed this afternoon at 13:45 and will end tomorrow at the same time. @usage drush site-alert:create "label name" "message" --start="2 hours 30 minutes" Create a site alert with the label and message that will be displayed 150 minutes from now and will remain visible until manually disabled or deleted. @usage drush site-alert:create "label name" "message" --end="15 minutes" Create a site alert with the label and message that will be displayed immediately and will disappear after 15 minutes.

Parameters

string $label: The label of the site alert. This is an internal identifier which will not be shown to end users.

string $message: The text content of the site alert.

array $options: Optional array of options keyed by option [start, end, severity].

File

src/Commands/SiteAlertCommands.php, line 81

Class

SiteAlertCommands
A Drush command file for the Site Alert module.

Namespace

Drupal\site_alert\Commands

Code

public function create(string $label, string $message, array $options = [
  'start' => NULL,
  'end' => NULL,
  'severity' => NULL,
  'active' => TRUE,
]) : int {
  $vars = [
    '@name' => 'site alert',
    '@label' => $label,
  ];
  try {
    $this->cli
      ->create($label, $message, $options);
  } catch (\Exception $e) {
    $this
      ->logger()
      ->error($e
      ->getMessage());
    return self::EXIT_FAILURE;
  }
  $this
    ->logger()
    ->success((string) dt("Created @name '@label'.", $vars));
  return self::EXIT_SUCCESS;
}