You are here

class RedirectSettingsCacheTag in Url Redirect 8.2

Same name and namespace in other branches
  1. 8 src/EventSubscriber/RedirectSettingsCacheTag.php \Drupal\url_redirect\EventSubscriber\RedirectSettingsCacheTag

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

Hierarchy

  • class \Drupal\url_redirect\EventSubscriber\RedirectSettingsCacheTag implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RedirectSettingsCacheTag

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

File

src/EventSubscriber/RedirectSettingsCacheTag.php, line 13

Namespace

Drupal\url_redirect\EventSubscriber
View source
class RedirectSettingsCacheTag implements EventSubscriberInterface {

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

  /**
   * Constructs a RedirectSettingsCacheTag 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 Redirect settings means that any cached page might
    // result in a different response, so we need to invalidate them all.
    $id = $event
      ->getConfig()
      ->get('id');
    if ($event
      ->getConfig()
      ->getName() === "url_redirect.url_redirect.{$id}") {
      $this->cacheTagsInvalidator
        ->invalidateTags([
        'rendered',
      ]);
    }
  }

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

}

Members

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