function FilterFormatRepository::getFormatsForAccount

Same name and namespace in other branches
  1. main core/modules/filter/src/FilterFormatRepository.php \Drupal\filter\FilterFormatRepository::getFormatsForAccount()
1 call to FilterFormatRepository::getFormatsForAccount()
FilterFormatRepository::getDefaultFormat in core/modules/filter/src/FilterFormatRepository.php

File

core/modules/filter/src/FilterFormatRepository.php, line 65

Class

FilterFormatRepository
Provides a repository service for filter formats.

Namespace

Drupal\filter

Code

public function getFormatsForAccount(AccountInterface $account) : array {
  $langcode = $this->languageManager
    ->getCurrentLanguage()
    ->getId();
  $uid = $account->id();
  $cid = "filter_formats:user:{$uid}:{$langcode}";
  if ($cached = $this->memoryCache
    ->get($cid)) {
    return $cached->data;
  }
  $formats = array_filter($this->getAllFormats(), fn(FilterFormatInterface $format): bool => $format->access('use', $account));
  $this->memoryCache
    ->set($cid, $formats, Cache::PERMANENT, $this->getCacheTags());
  return $formats;
}

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