function filter_formats in Zircon Profile 8.0
Same name and namespace in other branches
- 8 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.
See also
17 calls to filter_formats()
- BreadcrumbTest::testBreadCrumbs in core/
modules/ system/ src/ Tests/ Menu/ BreadcrumbTest.php - Tests breadcrumbs on node and administrative paths.
- DefaultViewsTest::createTerm in core/
modules/ views/ src/ Tests/ DefaultViewsTest.php - Returns a new term with random properties in vocabulary $vid.
- Editor::getAttachments in core/
modules/ editor/ src/ Plugin/ InPlaceEditor/ Editor.php - Returns the attachments for this editor.
- FilterCrudTest::testTextFormatCrud in core/
modules/ filter/ src/ Tests/ FilterCrudTest.php - Tests CRUD operations for text formats and filters.
- FilterFormat::getPossibleOptions in core/
modules/ filter/ src/ Plugin/ DataType/ FilterFormat.php - Returns an array of possible values with labels for display.
3 string references to 'filter_formats'
- drupal6.php in core/
modules/ migrate_drupal/ tests/ fixtures/ drupal6.php - A database agnostic dump for testing purposes.
- FilterAPITest::testDependencyRemoval in core/
modules/ filter/ src/ Tests/ FilterAPITest.php - Tests that filter format dependency removal works.
- filter_formats_reset in core/
modules/ filter/ filter.module - Resets the text format caches.
File
- core/
modules/ filter/ filter.module, line 96 - Framework for handling the filtering of content.
Code
function filter_formats(AccountInterface $account = NULL) {
$formats =& drupal_static(__FUNCTION__, array());
// All available formats are cached for performance.
if (!isset($formats['all'])) {
$language_interface = \Drupal::languageManager()
->getCurrentLanguage();
if ($cache = \Drupal::cache()
->get("filter_formats:{$language_interface->getId()}")) {
$formats['all'] = $cache->data;
}
else {
$formats['all'] = \Drupal::entityManager()
->getStorage('filter_format')
->loadByProperties(array(
'status' => TRUE,
));
uasort($formats['all'], 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
\Drupal::cache()
->set("filter_formats:{$language_interface->getId()}", $formats['all'], Cache::PERMANENT, \Drupal::entityManager()
->getDefinition('filter_format')
->getListCacheTags());
}
}
// If no user was specified, return all formats.
if (!isset($account)) {
return $formats['all'];
}
// Build a list of user-specific formats.
$account_id = $account
->id();
if (!isset($formats['user'][$account_id])) {
$formats['user'][$account_id] = array();
foreach ($formats['all'] as $format) {
if ($format
->access('use', $account)) {
$formats['user'][$account_id][$format
->id()] = $format;
}
}
}
return $formats['user'][$account_id];
}