Skip to content

Commit

Permalink
replace usage of user_role_names() deprecated in 10.2 and removed in …
Browse files Browse the repository at this point in the history
…11.0
  • Loading branch information
WengerK committed Apr 25, 2024
1 parent a1ce6f9 commit 78a2640
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- add cpsell project words for Gitlab-CI

### Changed
- replace usage of user_role_names() deprecated in 10.2 and removed in 11.0

## [4.0.1] - 2024-03-01
### Changed
- re-enable PHPUnit Symfony Deprecation notice
Expand Down
15 changes: 13 additions & 2 deletions template_whisperer.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

use Drupal\Core\Url;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;

/**
* Implements hook_install().
Expand Down Expand Up @@ -82,10 +84,19 @@ function template_whisperer_update_8001(&$sandbox) {
$roleStorage = \Drupal::service('entity_type.manager')
->getStorage('user_role');

$roles = Role::loadMultiple();
unset($roles[RoleInterface::ANONYMOUS_ID]);

// Get all roles with `administer template whisperer` permissions.
$roles_with_tw_administer = user_role_names(TRUE, 'administer template whisperer');
$roles_with_tw_administer = array_filter($roles, function ($role) {
return $role->hasPermission('administer template whisperer');
});
$roles_with_tw_administer = array_map(fn(RoleInterface $role) => $role->label(), $roles_with_tw_administer);
// Get all roles with `administer template whisperer suggestion entities.
$roles_with_tw_suggestion = user_role_names(TRUE, 'administer template whisperer suggestion entities');
$roles_with_tw_suggestion = array_filter($roles, function ($role) {
return $role->hasPermission('administer template whisperer suggestion entities');
});
$roles_with_tw_suggestion = array_map(fn(RoleInterface $role) => $role->label(), $roles_with_tw_suggestion);

$rids = array_merge($roles_with_tw_administer, $roles_with_tw_suggestion);
$rids = array_keys($rids);
Expand Down

0 comments on commit 78a2640

Please sign in to comment.