You are here

public function CliCommands::delete in Site Alert 8

Deletes site alert(s) with a matching label.

Parameters

string $label: The label to match for deletion.

Return value

int The number of deleted site alerts.

Throws

\InvalidArgumentException Thrown when the label is missing or is not a string.

\Drupal\Core\Entity\EntityStorageException Thrown when an error occurs during the deletion of a site alert.

Overrides CliCommandsInterface::delete

File

src/CliCommands.php, line 106

Class

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

Namespace

Drupal\site_alert

Code

public function delete(string $label) : int {
  if (empty($label) || !is_string($label)) {
    throw new \InvalidArgumentException('A label is required.');
  }
  $site_alerts = $this
    ->getAlertsByLabel($label);
  $count = count($site_alerts);
  $this->entityTypeManager
    ->getStorage('site_alert')
    ->delete($site_alerts);
  return $count;
}