Disable the "Generate automatic URL alias" checkbox for entities with existing paths

Created on 17 April 2017, over 7 years ago
Updated 4 April 2024, 9 months ago

Problem/Motivation

When enabling pathauto and configuring patterns, existing entities forms will display a marked "Generate automatic URL alias" checkbox, even thought the entity has an existing manual aliases.

While pathauto's update action can be configured to "Do nothing. Leave the old alias intact.", the UX of the form is misleading/confusing for content authors.

Proposed resolution

Disable the "Generate automatic URL alias" checkbox for entities with existing manual aliases.

Remaining tasks

  • Get consensus
  • Patch
  • Test

User interface changes

When authoring entity with existing manual alias, the "Generate automatic URL alias" checkbox will be unmarked.

API changes

None

Data model changes

None

Release notes snippet

TBD

Originally Reported

I have an existing content type that's been using custom URLs instead of a Pathauto for sometime, however, I would like to start using one soon.

My is problem is that once I enable the pattern all exiting content URLs will inevitably change to follow the pattern when they are next updated. I'd like to avoid this behavior for SEO and keep my old URLs intact, and only apply the pattern for new content (while selectively opting old content into the pattern).

It looks like the PathautoWidget class is responsible for this behavior. It feels like on my own I could use hook_field_widget_info_alter() to extend and alter this as I see fit, but am wondering if this could be an issue for other sites as well, so creating an issue here.

Ideally the "Generate automatic URL alias" box is not checked when an existing custom alias already in place, allowing the URL to remain intact during content updates. The editor can later opt the content into following the pattern should they choose to.

Thanks!

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States dunklea

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom Dubs

    Patch number 10 works for me. Can we please get this reviewed and committed?

    Just a note - if you have existing aliases (e.g. an existing site or from a migration) then the key_value table will contain the states, which will most likely be 1. So you can remove those entries from the key_value database if you still see the generate alias box ticked.

  • πŸ‡­πŸ‡ΊHungary suchdavid

    For me the patch wasn't applied correctly on "drupal/pathauto": "1.11.0"
    I re-created it for current stable version.

  • πŸ‡©πŸ‡ͺGermany Antares89 Schwerin

    Patch from #13 does not work. It always gets the last status from the key_value and this is normally 1 after the node has been created. This is why the 2nd if with $this->value === NULL is always wrong. The line with $this->value = $this->getOriginalValue(); should be removed.

    Patch from #12 works with Pathauto version 1.12.0

Production build 0.71.5 2024