4cb794ffd2bc59ef516013b91832dbf0caf2e3da
[yaffs-website] / web / core / modules / serialization / src / EventSubscriber / BcConfigSubscriber.php
1 <?php
2
3 namespace Drupal\serialization\EventSubscriber;
4
5 use Drupal\Core\Config\ConfigCrudEvent;
6 use Drupal\Core\Config\ConfigEvents;
7 use Drupal\Core\DrupalKernelInterface;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10 /**
11  * Config event subscriber to rebuild the container when BC config is saved.
12  */
13 class BcConfigSubscriber implements EventSubscriberInterface {
14
15   /**
16    * The Drupal Kernel.
17    *
18    * @var \Drupal\Core\DrupalKernelInterface
19    */
20   protected $kernel;
21
22   /**
23    * BcConfigSubscriber constructor.
24    *
25    * @param \Drupal\Core\DrupalKernelInterface $kernel
26    *   The Drupal Kernel.
27    */
28   public function __construct(DrupalKernelInterface $kernel) {
29     $this->kernel = $kernel;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function getSubscribedEvents() {
36     $events[ConfigEvents::SAVE][] = 'onConfigSave';
37     return $events;
38   }
39
40   /**
41    * Invalidates the service container if serialization BC config gets updated.
42    *
43    * @param \Drupal\Core\Config\ConfigCrudEvent $event
44    */
45   public function onConfigSave(ConfigCrudEvent $event) {
46     $saved_config = $event->getConfig();
47
48     if ($saved_config->getName() === 'serialization.settings') {
49       if ($event->isChanged('bc_primitives_as_strings') || $event->isChanged('bc_timestamp_normalizer_unix')) {
50         $this->kernel->invalidateContainer();
51       }
52     }
53   }
54
55 }