Problem/Motivation
user_update_notify_entity_update() reads the original user entity with $entity->original. Since Drupal 11.2, reading the original property is deprecated in favour of EntityInterface::getOriginal(), and the property is removed in Drupal 12 (see the change record).
- On Drupal 11.2+ every profile update by a targeted user triggers a deprecation notice: "Getting the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Entity\EntityInterface::getOriginal() instead."
- On Drupal 12,
$entity->originalisNULL, soUserUpdateNotifyFieldCompare::compare()throws aTypeErrorand saving the user fails with anEntityStorageException.
The module supports ^9.2 || ^10 || ^11, so getOriginal() can't simply replace the property: it doesn't exist before Drupal 11.2.
Steps to reproduce
- On Drupal 11.2 or later, enable the module, enable notifications, select a target role and at least one user field.
- Log in as a user with the target role and change the selected field on your own profile.
- The deprecation above is logged (or reported by PHPUnit when running the tests from #3631700: Add automated tests).
- On Drupal 12 (with the module and Token made compatible), the same steps fail with:
UserUpdateNotifyFieldCompare::compare(): Argument #1 ($original) must be of type Drupal\Core\Entity\EntityInterface, null given.
Proposed resolution
Use getOriginal() when it exists, and fall back to the original property on older cores:
// EntityInterface::getOriginal() was added in Drupal 11.2, and the // 'original' property was deprecated and is removed in Drupal 12. $original = method_exists($entity, 'getOriginal') ? $entity->getOriginal() : $entity->original;
This keeps support for Drupal 9.2 to 11.1, removes the deprecation on 11.2+, and works on Drupal 12. Once the module drops support for cores older than 11.2, the fallback can be removed.
Verified locally with the tests from #3631700: Add automated tests:
- Drupal 10.6 (fallback path): all tests pass.
- Drupal 11.4: all tests pass, and the deprecation is gone.
- Drupal 12.0-beta2 (with temporary compatibility changes for the module's info file and Token): all tests pass, including the 4 notification tests that previously failed.
Remaining tasks
- Review the MR.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork user_update_notify-3631702
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
beltofteComment #5
beltofteMarking as postponed as it depends on other issues to be solved / committed first.Wrong issue.
Comment #6
beltofteComment #8
beltofte