protected function CliCommands::getAlertsByLabel in Site Alert 8
Returns all site alerts that match the given label.
Parameters
string $label: The label to match.
bool|null $active: When TRUE or FALSE only active or inactive site alerts are returned. If NULL, both are returned.
Return value
\Drupal\site_alert\Entity\SiteAlert[] An array of site alert entities that match the label.
3 calls to CliCommands::getAlertsByLabel()
- CliCommands::delete in src/
CliCommands.php - Deletes site alert(s) with a matching label.
- CliCommands::disable in src/
CliCommands.php - Disables site alert(s).
- CliCommands::enable in src/
CliCommands.php - Enables a site alert.
File
- src/
CliCommands.php, line 170
Class
- CliCommands
- Service with shared code for CLI tools to perform common tasks.
Namespace
Drupal\site_alertCode
protected function getAlertsByLabel(string $label, ?bool $active = NULL) : array {
$site_alerts = [];
if (!empty($label)) {
$storage = $this->entityTypeManager
->getStorage('site_alert');
$query = $storage
->getQuery();
$query
->condition('label', $label, '=');
if ($active !== NULL) {
$query
->condition('active', $active);
}
$result = $query
->execute();
if (!empty($result)) {
$site_alerts = $storage
->loadMultiple($result);
}
}
return $site_alerts;
}