function filter_formats

Same name and namespace in other branches
  1. 10 core/modules/filter/filter.module \filter_formats()
  2. 9 core/modules/filter/filter.module \filter_formats()
  3. 8.9.x core/modules/filter/filter.module \filter_formats()
  4. 7.x modules/filter/filter.module \filter_formats()
  5. main 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.

Deprecated

in drupal:11.4.0 and is removed from drupal:13.0.0. Use the Drupal\filter\FilterFormatRepositoryInterface service with the ::getAllFormats() method to get all formats, or with the ::getFormatsForAccount() method to get all formats that a user is able to access.

See also

https://www.drupal.org/node/3035368

3 string references to 'filter_formats'
drupal6.php in core/modules/migrate_drupal/tests/fixtures/drupal6.php
A database agnostic dump for testing purposes.
drupal6.php in core/modules/contact/tests/fixtures/drupal6.php
A database agnostic dump for testing purposes.
drupal_static_reset in core/includes/bootstrap.inc
Resets one or all centrally stored static variable(s).

File

core/modules/filter/filter.module, line 34

Code

function filter_formats(?AccountInterface $account = NULL) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use the Drupal\\filter\\FilterFormatRepositoryInterface service with the ::getAllFormats() method to get all formats, or with the ::getFormatsForAccount() method to get all formats that a user is able to access. See https://www.drupal.org/node/3035368', E_USER_DEPRECATED);
  $filter_format_repository = \Drupal::service(FilterFormatRepositoryInterface::class);
  // If no user was specified, return all formats.
  if (!isset($account)) {
    return $filter_format_repository->getAllFormats();
  }
  return $filter_format_repository->getFormatsForAccount($account);
}

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