You are here

class BcConfigSubscriber in Drupal 8

Config event subscriber to rebuild the container when BC config is saved.

Hierarchy

  • class \Drupal\serialization\EventSubscriber\BcConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of BcConfigSubscriber

1 string reference to 'BcConfigSubscriber'
serialization.services.yml in core/modules/serialization/serialization.services.yml
core/modules/serialization/serialization.services.yml
1 service uses BcConfigSubscriber
serialization.bc_config_subscriber in core/modules/serialization/serialization.services.yml
Drupal\serialization\EventSubscriber\BcConfigSubscriber

File

core/modules/serialization/src/EventSubscriber/BcConfigSubscriber.php, line 13

Namespace

Drupal\serialization\EventSubscriber
View source
class BcConfigSubscriber implements EventSubscriberInterface {

  /**
   * The Drupal Kernel.
   *
   * @var \Drupal\Core\DrupalKernelInterface
   */
  protected $kernel;

  /**
   * BcConfigSubscriber constructor.
   *
   * @param \Drupal\Core\DrupalKernelInterface $kernel
   *   The Drupal Kernel.
   */
  public function __construct(DrupalKernelInterface $kernel) {
    $this->kernel = $kernel;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ConfigEvents::SAVE][] = 'onConfigSave';
    return $events;
  }

  /**
   * Invalidates the service container if serialization BC config gets updated.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   */
  public function onConfigSave(ConfigCrudEvent $event) {
    $saved_config = $event
      ->getConfig();
    if ($saved_config
      ->getName() === 'serialization.settings') {
      if ($event
        ->isChanged('bc_primitives_as_strings') || $event
        ->isChanged('bc_timestamp_normalizer_unix')) {
        $this->kernel
          ->invalidateContainer();
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BcConfigSubscriber::$kernel protected property The Drupal Kernel.
BcConfigSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
BcConfigSubscriber::onConfigSave public function Invalidates the service container if serialization BC config gets updated.
BcConfigSubscriber::__construct public function BcConfigSubscriber constructor.