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.
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:

Comments

jtor created an issue. See original summary.

velmir_taky’s picture

Status: Active » Needs review
StatusFileSize
new3.52 KB

Root cause

RedirectWidgetManager::submitRedirectWidgetForm() and getRedirectWidget() call isPublished(), setPublished(), and setUnpublished() on Redirect entities. These methods are provided by EntityPublishedTrait, which was only added to Redirect in redirect 1.12.0. Earlier versions (including 1.11.0 and below) do not implement EntityPublishedInterface, so these calls trigger a fatal error.

The redirect_widget composer.json requires drupal/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 EntityPublishedInterface checks:

- getRedirectWidget() line 92: disclaimer for unpublished redirects
- submitRedirectWidgetForm() line 197: prevent removal of published redirects in unpublished state
- submitRedirectWidgetForm() lines 220-232: publish/unpublish logic

When 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.

mauro_’s picture

Thanks 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!

  • mauro_ committed 72e5f996 on main
    #3574881: specify required redirect version for composer
    

  • mauro_ committed 72e5f996 on 1.0.x
    #3574881: specify required redirect version for composer
    
mauro_’s picture

Version: 1.0.0-beta1 » 1.0.0-beta2
Status: Needs review » Fixed

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.

mauro_’s picture

Version: 1.0.0-beta2 » 1.0.0-beta1
mauro_’s picture

Status: Fixed » Closed (fixed)