You are here

public function CliCommands::enable in Site Alert 8

Enables a site alert.

Parameters

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

Return value

int The number of site alerts that were enabled.

Throws

\Drupal\Core\Entity\EntityStorageException Thrown when an error occurs while enabling a site alert.

Overrides CliCommandsInterface::enable

File

src/CliCommands.php, line 144

Class

CliCommands
Service with shared code for CLI tools to perform common tasks.

Namespace

Drupal\site_alert

Code

public function enable(string $label) : int {
  $site_alerts = $this
    ->getAlertsByLabel($label, FALSE);
  if (empty($site_alerts)) {
    throw new \InvalidArgumentException(sprintf("No inactive site alerts found with the label '%s'.", $label));
  }
  $count = 0;
  foreach ($site_alerts as $site_alert) {
    $site_alert
      ->set('active', TRUE)
      ->save();
    $count++;
  }
  return $count;
}