Problem/Motivation

I deleted a content node, resulting in it moving to the trash. When I went to restore, it said it could not because there was already an item with the same URL alias. I tried restoring the URL alias and then the content node. That worked.

Proposed resolution

Have it restore the URL alias automatically when restoring a content node.

Remaining tasks

Implement.

User interface changes

Improved experience.

API changes

None.

Data model changes

None.

Issue fork trash-3576065

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

liam morland created an issue. See original summary.

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

kurttrowbridge’s picture

Status: Active » Needs review
Issue tags: +Chicago2026

I'm a little unsure about the correctness of this fix, but will submit it for feedback—see the provided MR.

I think the issue that was causing the incorrect error is the deleted condition. It doesn't look like notExists('deleted') in the validateRestore method's entity query correctly ignores items in the path_alias table that (because they got trashed along with the node they were aliasing) have a timestamp in the value. Changing that to a condition-based query seemed to get around that.

Then, I noticed that it caused two instances of the same alias to be restored: the original one got its deleted value removed, and a new one was created because Pathauto's hook_entity_update() got fired before the alias was restored (if I'm following correctly, when the node was restored, the new alias was generated). Moving the alias restoration into the preTrashRestore() method allowed me to restore a node, have its alias restored along with it, and not get any duplication. (I wonder whether postTrashRestore() still needs to keep the alias restoration too, but I left it there for now.

Thanks!

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

amateescu’s picture

@kurttrowbridge, thanks for looking into it! The problem is that Pathauto is creating duplicate aliases when restoring content, so I opened a new MR with a more comprehensive fix.

Btw, the notExists('deleted') condition is correct because the deleted field can be either NULL or a (recent) timestamp, but never 0 :)

  • amateescu committed 041c1e25 on 3.1.x
    fix: #3576065 Unable to restore item without first restoring its alias...

  • amateescu committed d9715fef on 3.x
    fix: #3576065 Unable to restore item without first restoring its alias...
amateescu’s picture

Version: 3.x-dev » 3.1.x-dev
Status: Needs review » Fixed

Merged!

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.

kurttrowbridge’s picture

Ahh, yeah, your MR makes much more sense and clears up what was really happening. :) Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.