filter_formats

5 filter.module filter_formats()
6 filter.module filter_formats($index = NULL)
7 filter.module filter_formats($account = NULL)
8 filter.module filter_formats($account = NULL)

Retrieve 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.

Return value

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

See also

filter_formats_reset()

14 calls to filter_formats()

3 string references to 'filter_formats'

File

modules/filter/filter.module, line 394
Framework for handling filtering of content.

Code

function filter_formats($account = NULL) {
  global $language;
  $formats = &drupal_static(__FUNCTION__, array());

  // All available formats are cached for performance.
  if (!isset($formats['all'])) {
    if ($cache = cache_get("filter_formats:{$language->language}")) {
      $formats['all'] = $cache->data;
    }
    else {
      $formats['all'] = db_select('filter_format', 'ff')
        ->addTag('translatable')
        ->fields('ff')
        ->condition('status', 1)
        ->orderBy('weight')
        ->execute()
        ->fetchAllAssoc('format');

      cache_set("filter_formats:{$language->language}", $formats['all']);
    }
  }

  // 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'];
}
Login or register to post comments