You are here

function filter_get_roles_by_format in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/filter/filter.module \filter_get_roles_by_format()
  2. 7 modules/filter/filter.module \filter_get_roles_by_format()
  3. 9 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
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
Framework for handling the filtering of content.

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) : [];
}