function filter_formats

Retrieves a list of text formats, ordered by weight.

Parameters

$account: (optional) If provided, only those formats that are allowed for this user account will be returned. All formats will be returned otherwise. Defaults to NULL.

Return value

An array of text format objects, keyed by the format ID and ordered by weight.

See also

filter_formats_reset()

21 calls to filter_formats()
BreadcrumbTest::testBreadCrumbs in drupal/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php
Tests breadcrumbs on node and administrative paths.
DefaultViewsTest::createTerm in drupal/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php
Returns a new term with random properties in vocabulary $vid.
Editor::getAttachments in drupal/core/modules/editor/lib/Drupal/editor/Plugin/InPlaceEditor/Editor.php
Implements \Drupal\edit\EditPluginInterface::getAttachments().
FilterCrudTest::testTextFormatCrud in drupal/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php
Tests CRUD operations for text formats and filters.
FilterFormatAccessTest::testFormatPermissions in drupal/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php
Tests the Filter format access permissions functionality.

... See full list

2 string references to 'filter_formats'
FilterAdminTest::testFilterAdmin in drupal/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php
Tests filter administration functionality.
filter_formats_reset in drupal/core/modules/filter/filter.module
Resets the text format caches.

File

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

Code

function filter_formats($account = NULL) {
  $language_interface = language(Language::TYPE_INTERFACE);
  $formats =& drupal_static(__FUNCTION__, array());

  // All available formats are cached for performance.
  if (!isset($formats['all'])) {
    if ($cache = cache()
      ->get("filter_formats:{$language_interface->langcode}")) {
      $formats['all'] = $cache->data;
    }
    else {
      $filter_formats = entity_load_multiple('filter_format');
      $formats['all'] = array();
      foreach ($filter_formats as $format_name => $filter_format) {
        if ($filter_format
          ->status()) {
          $formats['all'][$format_name] = $filter_format;
        }
      }
      uasort($formats['all'], 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
      cache()
        ->set("filter_formats:{$language_interface->langcode}", $formats['all'], CacheBackendInterface::CACHE_PERMANENT, array(
        'filter_formats' => TRUE,
      ));
    }
  }

  // Build a list of user-specific formats.
  if (isset($account) && !isset($formats['user'][$account->uid])) {
    $formats['user'][$account->uid] = array();
    foreach ($formats['all'] as $format) {
      if (filter_access($format, $account)) {
        $formats['user'][$account->uid][$format->format] = $format;
      }
    }
  }
  return isset($account) ? $formats['user'][$account->uid] : $formats['all'];
}