You are here

class GlobalredirectSettingsCacheTag in Global Redirect 8

A subscriber invalidating the 'rendered' cache tag when saving globalredirect settings.

Hierarchy

Expanded class hierarchy of GlobalredirectSettingsCacheTag

1 string reference to 'GlobalredirectSettingsCacheTag'
globalredirect.services.yml in ./globalredirect.services.yml
globalredirect.services.yml
1 service uses GlobalredirectSettingsCacheTag
globalredirect.settings_cache_tag in ./globalredirect.services.yml
Drupal\globalredirect\EventSubscriber\GlobalredirectSettingsCacheTag

File

src/EventSubscriber/GlobalredirectSettingsCacheTag.php, line 14
Contains \Drupal\globalredirect\EventSubscriber\GlobalredirectSettingsCacheTag.

Namespace

Drupal\globalredirect\EventSubscriber
View source
class GlobalredirectSettingsCacheTag implements EventSubscriberInterface {

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

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

  /**
   * Invalidate the 'rendered' cache tag whenever the settings are modified.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onSave(ConfigCrudEvent $event) {

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

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

}

Members

Namesort descending Modifiers Type Description Overrides
GlobalredirectSettingsCacheTag::$cacheTagsInvalidator protected property The cache tags invalidator.
GlobalredirectSettingsCacheTag::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
GlobalredirectSettingsCacheTag::onSave public function Invalidate the 'rendered' cache tag whenever the settings are modified.
GlobalredirectSettingsCacheTag::__construct public function Constructs a GlobalredirectSettingsCacheTag object.