function filter_get_formats_by_role

Same name and namespace in other branches
  1. 7.x modules/filter/filter.module \filter_get_formats_by_role()
  2. 8.9.x core/modules/filter/filter.module \filter_get_formats_by_role()
  3. 10 core/modules/filter/filter.module \filter_get_formats_by_role()
  4. 11.x core/modules/filter/filter.module \filter_get_formats_by_role()

Retrieves a list of text formats that are allowed for a given role.

Parameters

string $rid: The user role ID to retrieve text formats for.

Return value

\Drupal\filter\FilterFormatInterface[] An array of text format objects that are allowed for the role, keyed by the text format ID and ordered by weight.

1 call to filter_get_formats_by_role()
FilterFormatAccessTest::testFormatRoles in core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
Tests if text format is available to a role.

File

core/modules/filter/filter.module, line 169

Code

function filter_get_formats_by_role($rid) {
    $formats = [];
    foreach (filter_formats() as $format) {
        $roles = filter_get_roles_by_format($format);
        if (isset($roles[$rid])) {
            $formats[$format->id()] = $format;
        }
    }
    return $formats;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.