
| Current Path : /var/www/html/dataninja.cn/core/modules/color/src/EventSubscriber/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/dataninja.cn/core/modules/color/src/EventSubscriber/ColorConfigCacheInvalidator.php |
<?php
namespace Drupal\color\EventSubscriber;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\Core\Config\ConfigCrudEvent;
use Drupal\Core\Config\ConfigEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* A subscriber invalidating cache tags when color config objects are saved.
*/
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;
}
}