Problem/Motivation
Steps to reproduce
- Enable redirect_widget.
- Edit a node that shows the Redirect Widget sidebar.
- Enter a redirect destination and save.
Proposed resolution
- RedirectWidgetManager.php calls isPublished(), setPublished(), setUnpublished() on redirect entities.
- Redirect.php (1.11.0) does not provide these methods.
- Module should guard these calls (method_exists) or use a compatibility-safe approach.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | redirect_widget-fatal_error_setpublished-3574881-2.patch | 3.52 KB | velmir_taky |
Issue fork redirect_widget-3574881
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 #2
velmir_taky commentedRoot cause
RedirectWidgetManager::submitRedirectWidgetForm()andgetRedirectWidget()callisPublished(),setPublished(), andsetUnpublished()onRedirectentities. These methods are provided byEntityPublishedTrait, which was only added toRedirectin redirect 1.12.0. Earlier versions (including 1.11.0 and below) do not implementEntityPublishedInterface, so these calls trigger a fatal error.The redirect_widget
composer.jsonrequiresdrupal/redirect: ^1.0, which allows installing with any 1.x version including those without published state support.Fix
All five call sites are now guarded with
$entity instanceof EntityPublishedInterfacechecks:-
getRedirectWidget()line 92: disclaimer for unpublished redirects-
submitRedirectWidgetForm()line 197: prevent removal of published redirects in unpublished state-
submitRedirectWidgetForm()lines 220-232: publish/unpublish logicWhen the redirect entity does not support the published state (redirect < 1.12.0), the publish/unpublish logic is simply skipped and the redirect is saved as-is. The status message for new redirects is now shown regardless of published state support.
Comment #4
mauro_ commentedThanks for bringing this issue to light. However, I don't think it's a good solution to make this backwards compatible with older versions of the Redirect module, as this module was created and released after their release of 1.12. Whilst your fix seems fine, I fear that in the long run this will introduce unnecessary complexity in the code.
Therefore I will just specify the version of Redirect required for this module and link to this issue for those who want to patch to older versions.
I appreciate the effort!
Comment #7
mauro_ commentedComment #9
mauro_ commentedComment #10
mauro_ commented