Problem/Motivation

A bit like described in the Drupal 7 Alias Lock Module we often run into the situation that we have certain "static" content types, whose URL-aliases should be automatically created by pathauto, but never changed afterwards.
Of course this could be done manually by the author, but typically the content creators are no technical experts and tend to forget unchecking the "Generate automatic URL alias" after creating the node.

Typically, this is the case for nodes, which are an essential part of the menu structure or even more important, are parent paths to other URLs in a tree folder structure.

It would be nice to have an option, presumably on the pattern form (/admin/config/search/path/patterns/{CONTENT-TYPE}) to set this behavior.

Steps to reproduce

  1. Create an url pattern for nodes (e.g. page) with dynamic parts like [node:title]
  2. Create a node with a static nature (e.g. page) node, with automatic alias generation turned on. Let's set the title "My title"
  3. See the URL alias generated properly: /my-title
  4. Edit the node and change the title to "My new title" without thinking about the results in the URL and have /my-new-title generated as new title without noticing it
  5. Argue about the wrong url structure and unwanted redirects, because "the only thing you wanted to to is changing the title" ;)
  6. Hope for an automatic solution, locking the URL after first creation by automatically unchecking "Generate automatic URL alias".

:)

Proposed resolution

Add an option to the pattern create / edit form (/admin/config/search/path/patterns/{CONTENT-TYPE})

Remaining tasks

  1. Discuss
  2. Implement
  3. Write tests
  4. Rewiew
  5. Release

User interface changes

API changes

Data model changes

Issue fork pathauto-3345144

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

Anybody created an issue. See original summary.

anybody’s picture

@Maintainers: What do you think about this? If you'd be fine with that, we'd start the implementation. :)

mably’s picture

Could be an interesting feature to have.

Some kind of "Auto generate once only".

Having that pattern flag would mean to toggle off the state after an automatic path alias generation.

anybody’s picture

In the meantime I found https://www.drupal.org/project/node_keep

Maybe it should be linked on the module page. Looks like it solves this use-case?

mably’s picture

I think this feature could be implemented in-house.

We just need to find the right UX for it.

enertron’s picture

I would like to volunteer to implement this feature. How should the option be presented? Should it just be a toggle in a content type where an alias can be set, underneath the alias path field? Also, based on @anybody's original request, should there be an option on the pattern configuration page to have the "generate once" option set to "yes" by default?

anybody’s picture

Thanks @enertron!

Yes I think a checkbox per entity type would make sense, but we need to think about this existing global option and how it should interact with it or even get replaced by a per content type setting?

Update action
- Do nothing. Leave the old alias intact.
- Create a new alias. Leave the existing alias functioning.
- Create a new alias. Delete the old alias.
What should Pathauto do when updating an existing content item which already has an alias? The Redirect module settings affect whether a redirect is created when an alias is deleted.

I think this is something the maintainers should decide.

Some ideas for possible wordings:

  1. Disable "Generate automatic URL alias" after creating the initial alias
  2. Lock URL
  3. Only create URL initially

The first one is my favourite, because it's most clear to me and reuses the exact term from the entity edit form.

I think the UX is indeed very important here.

In the node we might just disable the "Generate automatic URL alias" checkbox

nicholass’s picture

FYI - We just discovered that something changed related to this, a bug from updating from 8.x-1.14 to 8.x-1.15 I guess the "Update Action" was not working correctly, ours was always set to "Create a new alias. Delete the old alias." but that never changed the "Pages" urls on save, on 1.15 that started working correctly I guess and messed up our pages urls on save, so we had to change it to "Do nothing. Leave the old alias intact.".

So in short now I need this feature as well, I can help test :D

Only affected like 10% of our pages, so must have been a change in Title detection changes or something some pages saved fine, others on save altered the paths on save, very odd...

anybody’s picture

@nicholass

Do nothing. Leave the old alias intact.

is indeed what you want in this case.

We typically use

Create a new alias. Delete the old alias.

in combination with the Redirect module by default as it's what we typically want for "dynamic" content where the URL should get updated if the token values are updated.

This has worked as expected since ever for us...

nicholass’s picture

Ill file a new issue since this could be a bug, that others may experience.

update: Sorry for the sidetrack, I believe this issue is with token module [node:menu-link:parent:url:path] is sometimes empty for some content, so its the one that changed behavior on us, not yours :D

enertron’s picture

In the node we might just disable the "Generate automatic URL alias" checkbox

I think that makes the most sense, although I think also including a note to clarify the behavior like "this page's alias will only be set once" would help the UX, otherwise the alias field and generate URL alias check will appear to be disabled for no apparent reason. With that in mind, should users with the privilege to administer pathauto have the ability to override that setting in the node form?

enertron’s picture

Small update, I'm still working on this. Requested features are implemented, but I want to have tests written in addition before I publish to this issue's fork.

enertron’s picture

@anybody hey, I've just updated this issue's fork and branch with my implementation for your request. You'll need to ensure your Drupal account has either permission "Administer pathauto" or "Administer URL aliases" to see the new checkbox in the page alias section.

Let me know your thoughts!

anybody’s picture

Status: Active » Needs review
anybody’s picture

Title: Add an option to disable auto-updating for certain content types » Add an option to enable / disable auto-updating for certain content types
Related issues: +#2660640: Add bulk enable "Generate automatic URL alias"/force option in bulk generate

Just came across this in the opposite direction! In an existing project it was DISABLED on all existing nodes for historic reasons, but should be enabled!

So we need both options, maybe as select per content type?

See these issues from history:

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

grevil’s picture

"3345144-add-an-option-alternate-per-pattern-approach" kind of went in the wrong direction, closing that one agian.

anybody’s picture

Priority: Normal » Minor
Status: Needs review » Postponed

As written in #14 this is mitigated by https://www.drupal.org/project/node_keep in most use-cases I have. So I'm marking this minor and would recommend linking it on the module page.

Still, we found some related UX issues, @grevil will open separate issues for these, and I think we can come back here, once solved, if still needed.

MR!180 is a valid option, but should also be checked UX-wise then.

grevil’s picture

grevil’s picture

Once that is solved (however the maintainer decides to fix it) we should continue here.