You are here

class ConfigCacheTag in Real Name 8

Same name and namespace in other branches
  1. 2.x src/EventSubscriber/ConfigCacheTag.php \Drupal\realname\EventSubscriber\ConfigCacheTag

A subscriber invalidating cache tags when realname config objects are saved.

Hierarchy

  • class \Drupal\realname\EventSubscriber\ConfigCacheTag implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ConfigCacheTag

1 string reference to 'ConfigCacheTag'
realname.services.yml in ./realname.services.yml
realname.services.yml
1 service uses ConfigCacheTag
realname.config_cache_tag in ./realname.services.yml
Drupal\realname\EventSubscriber\ConfigCacheTag

File

src/EventSubscriber/ConfigCacheTag.php, line 13

Namespace

Drupal\realname\EventSubscriber
View source
class ConfigCacheTag implements EventSubscriberInterface {

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

  /**
   * Constructs a RealnameCacheTag 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 cache tags when particular realname config objects are saved.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The Event to process.
   */
  public function onSave(ConfigCrudEvent $event) {

    // Check if realname settings object has been changed.
    if ($event
      ->getConfig()
      ->getName() === 'realname.settings') {

      // Clear the realname cache if the pattern was changed.
      realname_delete_all();

      // A change to the display-name pattern must invalidate the render cache
      // since the display-name could be used anywhere.
      $this->cacheTagsInvalidator
        ->invalidateTags([
        'rendered',
      ]);
    }
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigCacheTag::$cacheTagsInvalidator protected property The cache tags invalidator.
ConfigCacheTag::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ConfigCacheTag::onSave public function Invalidate cache tags when particular realname config objects are saved.
ConfigCacheTag::__construct public function Constructs a RealnameCacheTag object.