"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/color/src/EventSubscriber/ColorConfigCacheInvalidator.php" (26 Nov 2020, 1623 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ColorConfigCacheInvalidator.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 namespace Drupal\color\EventSubscriber;
    4 
    5 use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
    6 use Drupal\Core\Config\ConfigCrudEvent;
    7 use Drupal\Core\Config\ConfigEvents;
    8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    9 
   10 /**
   11  * A subscriber invalidating cache tags when color config objects are saved.
   12  */
   13 class ColorConfigCacheInvalidator implements EventSubscriberInterface {
   14 
   15   /**
   16    * The cache tags invalidator.
   17    *
   18    * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
   19    */
   20   protected $cacheTagsInvalidator;
   21 
   22   /**
   23    * Constructs a ColorConfigCacheInvalidator object.
   24    *
   25    * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
   26    *   The cache tags invalidator.
   27    */
   28   public function __construct(CacheTagsInvalidatorInterface $cache_tags_invalidator) {
   29     $this->cacheTagsInvalidator = $cache_tags_invalidator;
   30   }
   31 
   32   /**
   33    * Invalidate cache tags when a color theme config object changes.
   34    *
   35    * @param \Drupal\Core\Config\ConfigCrudEvent $event
   36    *   The Event to process.
   37    */
   38   public function onChange(ConfigCrudEvent $event) {
   39     // Changing a theme's color settings causes the theme's asset library
   40     // containing the color CSS file to be altered to use a different file.
   41     if (strpos($event->getConfig()->getName(), 'color.theme.') === 0) {
   42       $this->cacheTagsInvalidator->invalidateTags(['library_info']);
   43     }
   44   }
   45 
   46   /**
   47    * {@inheritdoc}
   48    */
   49   public static function getSubscribedEvents() {
   50     $events[ConfigEvents::SAVE][] = ['onChange'];
   51     $events[ConfigEvents::DELETE][] = ['onChange'];
   52 
   53     return $events;
   54   }
   55 
   56 }