Conversation
user_role_grant_permissions(), user_role_revoke_permissions() and user_role_change_permissions() are deprecated in drupal:11.5.0 and removed in drupal:13.0.0 (https://www.drupal.org/i/2025089, change record https://www.drupal.org/node/3348027). Each call is rewritten to the matching \Drupal\user\RoleInterface method on a role loaded with \Drupal\user\Entity\Role::loadOverrideFree(), the nullsafe chain core itself adopted in media_install() and node_install(). BC-wrapped: the static Role::loadOverrideFree() and the three RoleInterface methods all arrive with the deprecation itself (core e1f2b85d319, https://www.drupal.org/i/3620216), so the rewritten chain would fatal with "Call to undefined method" on Drupal < 11.5. Calls using named arguments, argument unpacking, or an argument count the deprecated functions never had are left untouched. First Drupal 11.5 rule, so it also adds config/drupal-11/drupal-11.5-deprecations.php and registers DRUPAL_115 in Drupal11SetList, drupal-11-all-deprecations.php and the composer-based DrupalSetProvider. The rule stays dormant until core branches 11.5: core's 11.x branch still reports VERSION = '11.4-dev' while already carrying the deprecation, so the version gate correctly declines to fire until then. Tested: commerce (6 files changed), search_api (3), webform (2), sitewide_alert (2), captcha (1), matomo (1), pwa (1), legal (1), profile (1) — 18 files, 57 call sites rewritten, all passing php -l
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #425.
Adds
ReplaceUserRolePermissionFunctionsRector, rewriting the three procedural user role permission helpers deprecated indrupal:11.5.0and removed indrupal:13.0.0:user_role_grant_permissions()→RoleInterface::grantPermissions()user_role_revoke_permissions()→RoleInterface::revokePermissions()user_role_change_permissions()→RoleInterface::changePermissions()Issue: https://www.drupal.org/i/2025089 · Change record: https://www.drupal.org/node/3348027
The role is loaded with the static
Role::loadOverrideFree()and chained with nullsafe operators — the pattern core itself adopted inmedia_install()andnode_install(). Calls using named arguments, argument unpacking, or an argument count the deprecated functions never had are left untouched.Why BC-wrapped
Both the static
ConfigEntityBase::loadOverrideFree()and the threeRoleInterfacemethods arrive with this deprecation (coree1f2b85d319, https://www.drupal.org/i/3620216), so the rewritten chain would fatal with "Call to undefined method" on Drupal < 11.5. Only the pre-existing storage methodConfigEntityStorage::loadOverrideFree()predates it, which is a different call shape — verified withgit grepagainste1f2b85d319~1.First Drupal 11.5 rule
There was no 11.5 set yet, so this also adds
config/drupal-11/drupal-11.5-deprecations.phpand registersDRUPAL_115in:src/Set/Drupal11SetList.phpconfig/drupal-11/drupal-11-all-deprecations.phpsrc/Set/DrupalSetProvider.php(composer-based selection — without this a site ondrupal/core ^11.5would never load the rule)DrupalSetProviderTestgains a data row pinning 11.5 cumulative matching.Reviewer note: the rule is dormant until core branches 11.5
Core's
11.xbranch still reportsVERSION = '11.4-dev'while already carrying the 11.5.0 deprecation — the constant is bumped at release-branch time.installedDrupalVersion()normalises that to11.4.0, so the11.5.0gate correctly declines to fire. Running this against today's11.x-devyields zero diffs by design. It activates once core reports 11.5.Validation
Live-tested against D11-compatible contrib with the version overridden to
11.5.0— 18 files / 57 call sites rewritten, all passingphp -l, none missed:Shapes covered: string literal and variable role IDs,
AccountInterface::ANONYMOUS_ROLE/RoleInterface::ANONYMOUS_IDconstants, chained$role->id(), multi-line permission arrays, and fully-qualified calls (\user_role_grant_permissions(, as matomo writes it) — that last one came out of reading real contrib and is now pinned by a fixture.Also verified: idempotent under a two-pass CLI run with
importNamesenabled (theisInBackwardsCompatibleCall()guard stops the rule re-firing on the call parked in thedeprecatedCallableslot).PHPStan messages captured against
drupal/core:11.x-devand added todocs/coverage-registry.php.Checks
vendor/bin/phpunit— 702 tests, 967 assertions, greencomposer phpstan— no errorscomposer fix-style— no changes