Problem/Motivation

on Drupal 10 saving content could trigger the following error:

Error: Call to undefined method Drupal\redirect_regex\Entity Redirect\Regex::getOriginal() in Drupal\Redirect_regex\Entity\RedirectRegex->postSave() (line 19 of modules/contrib/redirect_regex/src/Entity/RedirectRegex.php).
\Core\Entity\EntityStorageBase->doPostSave) (Line: 781)
\Core\Entity\ContentEntityStorageBase->doPostSave() (Line: 489)
\Core\Entity\EntityStorageBase->save()(Line:806)
\Core\Entity\Sql\SqlContentEntityStorage>save) (Line: 354)
\Core\Entity\EntityBase->save) (Line: 107)
redirect_path_alias_update()
call_user_func_array) (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\tclosurer) (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith) (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll) (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook() (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook) (Line: 564)
Drupal\Core\Entity\EntityStorageBase->doPostSave() (Line: 781)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave() (Line: 489)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 806)

The EntityInterface::getOriginal method is only available to Drupal 11+ but the module require ">=10".

Code used :

    if ($this->isRedirectRegex() || $this->isRedirectRegexEntity($this->getOriginal())) {

See https://www.drupal.org/node/3571065

Rewrites the deprecated $entity->original magic property, removed in drupal:12.0.0 (deprecated drupal:11.2.0, issue #3571065). Read accesses become $entity->getOriginal() and write assignments become $entity->setOriginal($value). Skips $this->original to avoid false positives on non-entity classes such as EntityTypeEvent and FieldStorageDefinitionEvent that have a legitimate $original property.
core_version_requirement: '>=10'

Proposed resolution

Create a version for D10, using $entity->original

Command icon 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:

  • 1.x Comparechanges, plain diff MR !5

Comments

o'briat created an issue. See original summary.

baikho made their first commit to this issue’s fork.

baikho’s picture

Status: Active » Needs review
codebymikey’s picture

Status: Needs review » Needs work

Added a comment about using the DeprecationHelper to handle this in a clean manner. So when we decide to fully drop D10 support, the legacy code can easily be removed with Rector.

But in order to use that API, we'll need to bump the minimum requirement, which I think is fine given the current Drupal end of life status for D10 - https://endoflife.date/drupal

  • codebymikey committed 656d3b19 on 1.x authored by baikho
    fix: #3605898 Use of the Drupal 11+ method EntityInterface::getOriginal...
codebymikey’s picture

Status: Needs work » Fixed

Thanks for the work done on this. Merged since tests pass on the 10.6 pipeline.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.