class DefaultIncidentStorage in Radioactivity 4.0.x
Same name and namespace in other branches
- 8.3 src/DefaultIncidentStorage.php \Drupal\radioactivity\DefaultIncidentStorage
Defines a default incident storage.
Hierarchy
- class \Drupal\radioactivity\DefaultIncidentStorage implements IncidentStorageInterface
Expanded class hierarchy of DefaultIncidentStorage
3 files declare their use of DefaultIncidentStorage
- DefaultIncidentStorageTest.php in tests/
src/ Unit/ DefaultIncidentStorageTest.php - RadioactivityFunctionTestTrait.php in tests/
src/ Traits/ RadioactivityFunctionTestTrait.php - StorageFactoryTest.php in tests/
src/ Unit/ StorageFactoryTest.php
1 string reference to 'DefaultIncidentStorage'
1 service uses DefaultIncidentStorage
File
- src/
DefaultIncidentStorage.php, line 10
Namespace
Drupal\radioactivityView source
class DefaultIncidentStorage implements IncidentStorageInterface {
/**
* The state key-value storage.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* DefaultIncidentStorage constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* The state key-value storage.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public function addIncident(IncidentInterface $incident) {
$incidents = $this->state
->get(self::STORAGE_KEY, []);
$incidents[] = $incident;
$this->state
->set(self::STORAGE_KEY, $incidents);
}
/**
* {@inheritdoc}
*/
public function getIncidents() {
return $this->state
->get(self::STORAGE_KEY, []);
}
/**
* {@inheritdoc}
*/
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 ?: [
[],
];
}
/**
* {@inheritdoc}
*/
public function clearIncidents() {
$this->state
->set(self::STORAGE_KEY, []);
}
/**
* {@inheritdoc}
*/
public function injectSettings(array &$page) {
global $base_url;
$page['#attached']['drupalSettings']['radioactivity']['type'] = 'default';
$page['#attached']['drupalSettings']['radioactivity']['endpoint'] = $base_url . '/radioactivity/emit';
}
}