protected function getRolesWithPermission() {
    $roles_with_perm = [];

    /* @var \Drupal\user\RoleInterface[] $roles */
    $roles = Role::loadMultiple();

    // Check for each role which one has permission to "view inappropriate
    // reports".
    foreach ($roles as $role) {
      if ($role->hasPermission('view inappropriate reports')) {
        $roles_with_perm[] = $role->id();
      }
    }

    return $roles_with_perm;
  }
protected function getRolesWithPermission() {
    $roles_with_perm = [];

    /* @var \Drupal\user\RoleInterface[] $roles */
    $roles = Role::loadMultiple();

    // Check for each role which one has permission to "view inappropriate
    // reports".
    foreach ($roles as $role) {
      if ($role->hasPermission('view inappropriate reports')) {
        $roles_with_perm[] = $role->id();
      }
    }

    return $roles_with_perm;
  }
protected function getRolesWithPermission ( ) { $ roles_with_perm = [ ] ; /* @var \Drupal\user\RoleInterface[] $roles */ $ roles = Role :: loadMultiple ( ) ; // Check for each role which one has permission to "view inappropriate // reports". foreach ( $ roles as $ role ) { if ( $ role -> hasPermission ( 'view inappropriate reports' ) ) { $ roles_with_perm [ ] = $ role -> id ( ) ; } } return $ roles_with_perm ; }
Returns the role with the required permission.

@return array
A list of Role IDs.
Returns the role with the required permission .