class ColorConfigCacheInvalidator

Same name in other branches
  1. 9 core/modules/color/src/EventSubscriber/ColorConfigCacheInvalidator.php \Drupal\color\EventSubscriber\ColorConfigCacheInvalidator

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

Hierarchy

Expanded class hierarchy of ColorConfigCacheInvalidator

1 string reference to 'ColorConfigCacheInvalidator'
color.services.yml in core/modules/color/color.services.yml
core/modules/color/color.services.yml
1 service uses ColorConfigCacheInvalidator
color.config_cache_invalidator in core/modules/color/color.services.yml
Drupal\color\EventSubscriber\ColorConfigCacheInvalidator

File

core/modules/color/src/EventSubscriber/ColorConfigCacheInvalidator.php, line 13

Namespace

Drupal\color\EventSubscriber
View source
class ColorConfigCacheInvalidator implements EventSubscriberInterface {
    
    /**
     * The cache tags invalidator.
     *
     * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
     */
    protected $cacheTagsInvalidator;
    
    /**
     * Constructs a ColorConfigCacheInvalidator 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 a color theme config object changes.
     *
     * @param \Drupal\Core\Config\ConfigCrudEvent $event
     *   The Event to process.
     */
    public function onChange(ConfigCrudEvent $event) {
        // Changing a theme's color settings causes the theme's asset library
        // containing the color CSS file to be altered to use a different file.
        if (strpos($event->getConfig()
            ->getName(), 'color.theme.') === 0) {
            $this->cacheTagsInvalidator
                ->invalidateTags([
                'library_info',
            ]);
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() {
        $events[ConfigEvents::SAVE][] = [
            'onChange',
        ];
        $events[ConfigEvents::DELETE][] = [
            'onChange',
        ];
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary
ColorConfigCacheInvalidator::$cacheTagsInvalidator protected property The cache tags invalidator.
ColorConfigCacheInvalidator::getSubscribedEvents public static function
ColorConfigCacheInvalidator::onChange public function Invalidate cache tags when a color theme config object changes.
ColorConfigCacheInvalidator::__construct public function Constructs a ColorConfigCacheInvalidator object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.