protected function LocaleLookup::getCid in Drupal 8
Same name and namespace in other branches
- 9 core/modules/locale/src/LocaleLookup.php \Drupal\locale\LocaleLookup::getCid()
Gets the cache ID.
Return value
string
Overrides CacheCollector::getCid
File
- core/
modules/ locale/ src/ LocaleLookup.php, line 110
Class
- LocaleLookup
- A cache collector to allow for dynamic building of the locale cache.
Namespace
Drupal\localeCode
protected function getCid() {
if (!isset($this->cid)) {
// Add the current user's role IDs to the cache key, this ensures that,
// for example, strings for admin menu items and settings forms are not
// cached for anonymous users.
$user = \Drupal::currentUser();
$rids = $user ? implode(':', $user
->getRoles()) : '';
$this->cid = "locale:{$this->langcode}:{$this->context}:{$rids}";
// Getting the roles from the current user might have resulted in t()
// calls that attempted to get translations from the locale cache. In that
// case they would not go into this method again as
// CacheCollector::lazyLoadCache() already set the loaded flag. They would
// however call resolveCacheMiss() and add that string to the list of
// cache misses that need to be written into the cache. Prevent that by
// resetting that list. All that happens in such a case are a few uncached
// translation lookups.
$this->keysToPersist = [];
}
return $this->cid;
}