-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ConfigSubscriber.php
43 lines (37 loc) · 1.32 KB
/
ConfigSubscriber.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Drupal\woot\EventSubscriber;
use Drupal\Core\Config\ConfigEvents;
use Drupal\Core\Config\ConfigImporterEvent;
use Drupal\Core\Config\ConfigImportValidateEventSubscriberBase;
/**
* Subscribes to Symfony events and maps them to Rules events.
*/
class ConfigSubscriber extends ConfigImportValidateEventSubscriberBase
{
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array
{
$events = [];
// In this example, we would use information from the State API to determine
// what events we should subscribe to. Suffice it to say we trust that the
// State API works correctly, so we're only going to check if the service is
// available here to make our point.
if (\Drupal::hasService('state')) {
$events[ConfigEvents::IMPORT_VALIDATE][] = 'onConfigImporterValidate';
}
return $events;
}
/**
* {@inheritdoc}
*/
public function onConfigImporterValidate(ConfigImporterEvent $event)
{
// Always log an error, except when there has been a state key set that explicitly disables this functionality.
if (!\Drupal::state()->get('woot.shoud_not_fail_on_cim')) {
$importer = $event->getConfigImporter();
$importer->logError($this->t('woot config error'));
}
}
}