Repository navigation
feat: add ReplaceUserRolePermissionFunctionsRector for Drupal 11.5 (#425) - #426
Merged
Merged
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 was referenced Sep 19, 2026
Merged
…services (#431) (#432) * feat: replace user_login_finalize()/user_logout() with the finalizer services user_login_finalize() and user_logout() are deprecated in drupal:11.5.0 and removed in drupal:13.0.0 (https://www.drupal.org/i/2012976, change record https://www.drupal.org/node/3379194). Core moved both function bodies verbatim into two new services (drupal-core accb9caa1fc), so the mapping is 1-to-1 and two FunctionToServiceRector entries cover it: user_login_finalize($account) -> \Drupal::service(\Drupal\user\LoginFinalizer::class)->finalizeLogin($account) user_logout() -> \Drupal::service(\Drupal\user\LogoutFinalizer::class)->finalizeLogout() BC-wrapped: LoginFinalizer and LogoutFinalizer are added by the deprecation commit itself, so the rewritten call fatals on Drupal < 11.5. The digest rule guards against named arguments, because the service parameter is $user where the deprecated function's was $account. That guard is not reproduced here: no contrib project calls either function with a named or extra argument, so the generic rector's verbatim argument pass-through is safe. If a guard is wanted it belongs on FunctionToServiceRector itself, where it would cover every function-to-service rule at once. Neither the deprecated functions nor the service methods take a parameter by reference, so the wrapper emits arrow functions rather than long closures. Verified idempotent with importNames(true): a second pass is a no-op, and the void return types produce no phpstan function.void. * docs: record the PHPStan messages the finalizer rules cover Captured live against drupal/core 11.x-dev with externalauth and openid_connect installed, normalised through scripts/normalize-phpstan-message.php, and folded into docs/coverage-registry.php. * feat: add ReplaceFileSaveUploadFunctionsRector for Drupal 11.5 (#434) file_save_upload(), file_managed_file_save_upload() and _file_save_upload_from_form() are deprecated in drupal:11.5.0 and removed in drupal:13.0.0 (https://www.drupal.org/i/3375423, change record https://www.drupal.org/node/3382414). Core moved each function body into a new service (drupal-core e8424495f0d) and left the function delegating to it: file_save_upload($name, $validators, $destination, $delta, $fileExists) -> \Drupal::service(\Drupal\file\Upload\FormFileUploader::class) ->saveFormUploadedFiles(...) file_managed_file_save_upload($element, $form_state) -> \Drupal::service(\Drupal\file\Upload\ManagedFileElementHelper::class) ->managedFileSaveUpload(...) _file_save_upload_from_form($element, $form_state, $delta, $fileExists) -> \Drupal::service(\Drupal\file\Upload\ManagedFileElementHelper::class) ->saveFileUploads(...) Not a FunctionToServiceRector config entry, because the wrapper also normalised its arguments where the service methods do not. file_save_upload() turned a FALSE/NULL $destination into 'temporary://' before delegating, and saveFormUploadedFiles() types that parameter string — a verbatim pass-through would hand the service a bool and fatal. That is the dominant contrib shape: a literal FALSE or NULL third argument appears in 47 files across the contrib index (tmgmt, file_replace, paragraphs_browser, bootstrap_italia, dxpr_theme, site_verify, micon, ...), so the rector rewrites the literal. Both functions also ran a legacy int $fileExists through FileExists::fromLegacyInt(), while the service parameters accept only the enum. A FileSystemInterface::EXISTS_* constant is already converted by the drupal-10.3 set, so the only shape left is a bare integer literal; such a call is skipped rather than rewritten into a TypeError. No contrib project passes one today. BC-wrapped: FormFileUploader and ManagedFileElementHelper arrive with the deprecation itself (git grep at e8424495f0d~1 finds neither), so the rewritten call fatals on Drupal < 11.5. Neither the deprecated functions nor the service methods take a parameter by reference, so the wrapper emits arrow functions, and all three methods return a value, so no phpstan function.void. Live-tested against D11-compatible contrib on core 11.x-dev: gin_login (27,767 installs), media_entity_file_replace (23,146), tmgmt (11,680), file_replace (10,008), paragraphs_browser (9,901), responsive_favicons (4,017), gutenberg (2,790), file_history — 8 call sites rewritten across all three functions, including the FALSE and NULL destination shapes and a call already using FileExists::Replace. plupload was a no-change: its only occurrence is an @see docblock, correctly left alone. Verified idempotent with importNames(true) — a second pass is a no-op. PHPSTAN_MESSAGES captured from those modules and normalised with scripts/normalize-phpstan-message.php; docs/coverage-registry.php regenerated.
…sion-functions-2025089
…sion-functions-2025089
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