You are here

class ConfigSubscriber in Analytics 8

Analytics ConfigSubscriber.

Hierarchy

  • class \Drupal\analytics\EventSubscriber\ConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ConfigSubscriber

1 string reference to 'ConfigSubscriber'
analytics.services.yml in ./analytics.services.yml
analytics.services.yml
1 service uses ConfigSubscriber
analytics.config_subscriber in ./analytics.services.yml
Drupal\analytics\EventSubscriber\ConfigSubscriber

File

src/EventSubscriber/ConfigSubscriber.php, line 13

Namespace

Drupal\analytics\EventSubscriber
View source
class ConfigSubscriber implements EventSubscriberInterface {

  /**
   * The cache tags invalidator.
   *
   * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
   */
  protected $cacheTagsInvalidator;

  /**
   * Constructs a new ConfigSubscriber.
   *
   * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
   *   The cache tags invalidator.
   */
  public function __construct(CacheTagsInvalidatorInterface $cache_tags_invalidator) {
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
  }

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

  /**
   * Respond to the config save event.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onConfigSave(ConfigCrudEvent $event) {

    // Changing the Analytics settings means that any cached page might
    // result in a different response, so we need to invalidate them all.
    if ($event
      ->getConfig()
      ->getName() === 'analytics.settings') {
      $this->cacheTagsInvalidator
        ->invalidateTags([
        'rendered',
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigSubscriber::$cacheTagsInvalidator protected property The cache tags invalidator.
ConfigSubscriber::getSubscribedEvents public static function
ConfigSubscriber::onConfigSave public function Respond to the config save event.
ConfigSubscriber::__construct public function Constructs a new ConfigSubscriber.