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
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.
Code
modules/filter/filter.module, line 331
<?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 