Same name and namespace in other branches
  1. 4.6.x modules/filter.module \filter_formats()
  2. 4.7.x modules/filter.module \filter_formats()
  3. 5.x modules/filter/filter.module \filter_formats()
  4. 6.x modules/filter/filter.module \filter_formats()
  5. 7.x modules/filter/filter.module \filter_formats()
  6. 9 core/modules/filter/filter.module \filter_formats()

Retrieves a list of enabled text formats, ordered by weight.

Parameters

\Drupal\Core\Session\AccountInterface|null $account: (optional) If provided, only those formats that are allowed for this user account will be returned. All enabled formats will be returned otherwise. Defaults to NULL.

Return value

\Drupal\filter\FilterFormatInterface[] An array of text format objects, keyed by the format ID and ordered by weight.

See also

filter_formats_reset()

18 calls to filter_formats()
BreadcrumbTest::testBreadCrumbs in core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php
Tests breadcrumbs on node and administrative paths.
DefaultViewsTest::createTerm in core/modules/views/tests/src/Functional/DefaultViewsTest.php
Returns a new term with random properties in vocabulary $vid.
Editor::getAttachments in core/modules/editor/src/Plugin/InPlaceEditor/Editor.php
Returns the attachments for this editor.
FilterCrudTest::testTextFormatCrud in core/modules/filter/tests/src/Kernel/FilterCrudTest.php
Tests CRUD operations for text formats and filters.
FilterFormat::getPossibleOptions in core/modules/filter/src/Plugin/DataType/FilterFormat.php
Returns an array of possible values with labels for display.

... See full list

4 string references to 'filter_formats'
FilterAPITest::testDependencyRemoval in core/modules/filter/tests/src/Kernel/FilterAPITest.php
Tests that filter format dependency removal works.
FilterFormatTest::providerSource in core/modules/filter/tests/src/Kernel/Plugin/migrate/source/d6/FilterFormatTest.php
The data provider.
filter_formats_reset in core/modules/filter/filter.module
Resets the text format caches.
RoleTest::providerSource in core/modules/user/tests/src/Kernel/Plugin/migrate/source/d6/RoleTest.php
The data provider.

File

core/modules/filter/filter.module, line 97
Framework for handling the filtering of content.

Code

function filter_formats(AccountInterface $account = NULL) {
  $formats =& drupal_static(__FUNCTION__, []);

  // All available formats are cached for performance.
  if (!isset($formats['all'])) {
    $language_interface = \Drupal::languageManager()
      ->getCurrentLanguage();
    if ($cache = \Drupal::cache()
      ->get("filter_formats:{$language_interface->getId()}")) {
      $formats['all'] = $cache->data;
    }
    else {
      $formats['all'] = \Drupal::entityTypeManager()
        ->getStorage('filter_format')
        ->loadByProperties([
        'status' => TRUE,
      ]);
      uasort($formats['all'], 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
      \Drupal::cache()
        ->set("filter_formats:{$language_interface->getId()}", $formats['all'], Cache::PERMANENT, \Drupal::entityTypeManager()
        ->getDefinition('filter_format')
        ->getListCacheTags());
    }
  }

  // If no user was specified, return all formats.
  if (!isset($account)) {
    return $formats['all'];
  }

  // Build a list of user-specific formats.
  $account_id = $account
    ->id();
  if (!isset($formats['user'][$account_id])) {
    $formats['user'][$account_id] = [];
    foreach ($formats['all'] as $format) {
      if ($format
        ->access('use', $account)) {
        $formats['user'][$account_id][$format
          ->id()] = $format;
      }
    }
  }
  return $formats['user'][$account_id];
}