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
- Create an url pattern for nodes (e.g. page) with dynamic parts like
[node:title] - Create a node with a static nature (e.g. page) node, with automatic alias generation turned on. Let's set the title "My title"
- See the URL alias generated properly:
/my-title - Edit the node and change the title to "My new title" without thinking about the results in the URL and have
/my-new-titlegenerated as new title without noticing it - Argue about the wrong url structure and unwanted redirects, because "the only thing you wanted to to is changing the title" ;)
- 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
- Discuss
- Implement
- Write tests
- Rewiew
- Release
User interface changes
API changes
Data model changes
Issue fork pathauto-3345144
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
anybody@Maintainers: What do you think about this? If you'd be fine with that, we'd start the implementation. :)
Comment #3
mably commentedCould 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.
Comment #4
anybodyIn 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?
Comment #5
mably commentedI think this feature could be implemented in-house.
We just need to find the right UX for it.
Comment #6
enertron commentedI 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?
Comment #7
anybodyThanks @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?
I think this is something the maintainers should decide.
Some ideas for possible wordings:
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
Comment #8
nicholassFYI - 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...
Comment #9
anybody@nicholass
is indeed what you want in this case.
We typically use
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...
Comment #10
nicholassIll 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
Comment #11
enertron commentedI 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?
Comment #12
enertron commentedSmall 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.
Comment #13
enertron commented@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!
Comment #15
anybodyComment #16
anybodyJust 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:
Comment #19
grevil commented"3345144-add-an-option-alternate-per-pattern-approach" kind of went in the wrong direction, closing that one agian.
Comment #20
anybodyAs 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.
Comment #21
grevil commentedPostponed on https://www.drupal.org/project/pathauto/issues/3627053.
Comment #22
grevil commentedOnce that is solved (however the maintainer decides to fix it) we should continue here.