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
Issue fork redirect_regex-3605898
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
baikho commentedComment #5
codebymikey commentedAdded a comment about using the
DeprecationHelperto 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
Comment #7
codebymikey commentedThanks for the work done on this. Merged since tests pass on the 10.6 pipeline.