function filter_get_roles_by_format

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

Retrieves a list of roles that are allowed to use a given text format.

Parameters

\Drupal\filter\FilterFormatInterface $format: An object representing the text format.

Return value

array An array of role names, keyed by role ID.

7 calls to filter_get_roles_by_format()
FilterDefaultConfigTest::testInstallation in core/modules/filter/tests/src/Kernel/FilterDefaultConfigTest.php
Tests installation of default formats.
FilterDefaultConfigTest::testUpdateRoles in core/modules/filter/tests/src/Kernel/FilterDefaultConfigTest.php
Tests that changes to FilterFormat::$roles do not have an effect.
FilterFormatAccessTest::testFormatRoles in core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
Tests if text format is available to a role.
FilterFormatEditForm::form in core/modules/filter/src/FilterFormatEditForm.php
Gets the actual form array to be built.
FilterFormatFormBase::form in core/modules/filter/src/FilterFormatFormBase.php
Gets the actual form array to be built.

... See full list

File

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

Code

function filter_get_roles_by_format(FilterFormatInterface $format) {
    // Handle the fallback format upfront (all roles have access to this format).
    if ($format->isFallbackFormat()) {
        return user_role_names();
    }
    // Do not list any roles if the permission does not exist.
    $permission = $format->getPermissionName();
    return !empty($permission) ? user_role_names(FALSE, $permission) : [];
}

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