filter_formats

Versions
4.6 – 5
filter_formats()
6
filter_formats($index = NULL)
7
filter_formats($account = NULL)

Retrieve a list of text formats, ordered by weight.

See also

filter_formats_reset()

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.

▾ 7 functions call filter_formats()

filter_admin_overview in modules/filter/filter.admin.inc
Menu callback; Displays a list of all text formats and allows them to be rearranged.
filter_default_format in modules/filter/filter.module
Returns the ID of the default text format for a particular user.
filter_form in modules/filter/filter.module
Generates a selector for choosing a format in a form.
filter_format_load in modules/filter/filter.module
Load a text format object from the database.
filter_get_formats_by_role in modules/filter/filter.module
Retrieves a list of text formats that are allowed for a given role.
filter_permission in modules/filter/filter.module
Implement hook_permission().
_filter_tips in modules/filter/filter.module
Helper function for fetching filter tips.

Code

modules/filter/filter.module, line 332

<?php
function filter_formats($account = NULL) {
  $formats = &drupal_static(__FUNCTION__, array());

  // Statically cache all existing formats upfront.
  if (!isset($formats['all'])) {
    $formats['all'] = db_select('filter_format', 'ff')
      ->addTag('translatable')
      ->fields('ff')
      ->orderBy('weight')
      ->execute()
      ->fetchAllAssoc('format');
  }

  // 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
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.