You are here

public function DefaultIncidentStorage::getIncidentsByType in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x src/DefaultIncidentStorage.php \Drupal\radioactivity\DefaultIncidentStorage::getIncidentsByType()

Gets all incidents from the storage per entity type.

Parameters

string $entity_type: Entity type for selection. Default to all entity types.

Return value

\Drupal\radioactivity\IncidentInterface[][] Array of incident objects keyed by entity type (1st) and entity ID (2nd).

Overrides IncidentStorageInterface::getIncidentsByType

File

src/DefaultIncidentStorage.php, line 48

Class

DefaultIncidentStorage
Defines a default incident storage.

Namespace

Drupal\radioactivity

Code

public function getIncidentsByType($entity_type = '') {
  $incidents = [];

  /** @var \Drupal\radioactivity\IncidentInterface[] $stored_incidents */
  $stored_incidents = $this->state
    ->get(self::STORAGE_KEY, []);
  foreach ($stored_incidents as $incident) {
    $incidents[$incident
      ->getEntityTypeId()][$incident
      ->getEntityId()][] = $incident;
  }
  if (isset($incidents[$entity_type])) {
    return [
      $entity_type => $incidents[$entity_type],
    ];
  }
  return $incidents ?: [
    [],
  ];
}