Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / locale / src / EventSubscriber / LocaleTranslationCacheTag.php
1 <?php
2
3 namespace Drupal\locale\EventSubscriber;
4
5 use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
6 use Drupal\locale\LocaleEvents;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9 /**
10  * A subscriber invalidating cache tags when translating a string.
11  */
12 class LocaleTranslationCacheTag implements EventSubscriberInterface {
13
14   /**
15    * The cache tags invalidator.
16    *
17    * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
18    */
19   protected $cacheTagsInvalidator;
20
21   /**
22    * Constructs a LocaleTranslationCacheTag object.
23    *
24    * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
25    *   The cache tags invalidator.
26    */
27   public function __construct(CacheTagsInvalidatorInterface $cache_tags_invalidator) {
28     $this->cacheTagsInvalidator = $cache_tags_invalidator;
29   }
30
31   /**
32    * Invalidate cache tags whenever a string is translated.
33    */
34   public function saveTranslation() {
35     $this->cacheTagsInvalidator->invalidateTags(['rendered', 'locale']);
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public static function getSubscribedEvents() {
42     $events[LocaleEvents::SAVE_TRANSLATION][] = ['saveTranslation'];
43     return $events;
44   }
45
46 }