Problem/Motivation
When trying to set a custom alias for a node that previously had an automatic alias, but for which the pattern was removed, the custom alias does not get saved.
Step to reproduce
- Create a content type.
- Create a pattern which applies to this content type.
- Create a node with an automatic alias.
- Remove the pattern.
- Edit the node. Notice that the checkbox "Generate automatic URL alias" no longer appears, cause there is no longer a pattern that applies to the content type. Try to set a custom alias and save the node.
Expected result: the alias for the node is changed to the custom alias.
Actual result: the alias has not been changed.
Proposed resolution
Possible solutions:
- On the widget
\Drupal\pathauto\PathautoWidget
, set the "pathauto" property explicitly toPathautoState::SKIP
when there is no pattern found for the entity.
Cons- May not fix the issue when updating entities using REST?
- In
\Drupal\pathauto\PathautoItem::postSave()
also execute the parent'spostSave()
when there is no pattern found for the entity.
Cons- When setting the pathauto state explicitly to
PathautoState::CREATE
, it is no longer guaranteed that the existing alias is preserved.
- When setting the pathauto state explicitly to
Original report by sukanya.ramakrishnan
Hello,
I am trying to enter a URL alias on an article content and i find that it is not getting updated on the node.
I have the pathauto module installed. I dont have any patterns setup to auto generate any aliases.
Ideally, i would think that the url alias i entered for the article would be saved, but when i debugged, i found that the path module code is not getting executed and pathauto seems to override the path module in this case. I wanted some help to understand how this works. Will really appreciate if someone can throw some light on this.
Thanks
Sukanya
Comment | File | Size | Author |
---|---|---|---|
#28 | 2756703-28.patch | 4.48 KB | amateescu |
| |||
#28 | 2756703-28-test-only.patch | 3.68 KB | amateescu |
#27 | pathauto-custom-alias-2756703-27.patch | 822 bytes | jasonawant |
#27 | interdiff_23-27.txt | 6.51 KB | jasonawant |
#23 | pathauto-custom-alias-2756703-23.patch | 7.36 KB | MegaChriz |
|
Comments
Comment #2
sukanya.ramakrishnan CreditAttribution: sukanya.ramakrishnan commentedComment #3
sukanya.ramakrishnan CreditAttribution: sukanya.ramakrishnan commentedComment #4
esclapes CreditAttribution: esclapes as a volunteer commentedI am also seeing this behaviour. In my case only for taxonomy terms that were created during a custom migration by the "entity lookup & create" process plugin.
URL alias are not updated when pathauto is enabled with default settings. Saving the taxonomy term does not change the alias value.
However, newly created terms do get their alias created and update works as expected.
I guess there is something on the migrated record that triggers this bug, but disabling pathauto fixes the issue. The records look the same on database:
The
recerca
term was imported without alias, and later updated diabling pahauto, and cannot be changed once pathauto is enabled again. Thetest-term
term was newly created with patauto enabled.I have looked at devel output for each term (attached) and I don't see any differece. Is there any other path-realted data that I could compare?
I am using latest dev and latest dependencies.
Comment #5
esclapes CreditAttribution: esclapes as a volunteer commentedComment #6
BerdirI think there two different things here.
Notes:
* You're the first to report this about the non-working manual alias. I've never noticed something like that, e.g. when not having any aliases on users. Should be relatively easy to write a test for.
* About not updating existing entities, pathauto tracks whether the checkbox to automatically create an alias was checked and will not attempt to later create an alias if that was originally checked. You can see that by going to the edit form and then the checkbox is not checked by default. That shouldn't be checked by default however. Usually aliases are created without problem on migrations, done that myself, although not on terms..
Comment #7
esclapes CreditAttribution: esclapes as a volunteer commentedThanks for your reply. In my case, there was not pattern configured for the taxonomy terms, and thus there was no checkbox. It just failed to update silently.
I have just configured a pattern and bulk generated aliases for this vocabulary. After that, they work as expected and I am able to manually update the alias by unchecking the automatic generation and typing a different alias. Before, there was no checkbox and alias did not update.
I still think there might be some edge case that triggers this behaviour, but I am not able to reproduce it on a test site.
Just note for further reference that my terms were created with the Entity Lookup & Generate plugin, and there is no path generated on import in that case, as they are auto-generated from term name while migrating nodes.
Comment #8
Beanjammin CreditAttribution: Beanjammin at emedia.ca commentedI just ran into this issue where I had installed but not configured pathauto. Filling in the manual URL alias field as provided by the Path module and then saving the content resulted in no URL alias being saved. This was done on a stock Basic Page content type on drupal 8.1.10. Uninstalling pathauto fixed the problem.
Comment #9
mike.vindicate CreditAttribution: mike.vindicate commentedI have the same issue.
Step to reproduce:
Now adjustments to save the url alias will never work.
It does work if you add an alias manually via the alias overview admin page.
When i re-add the pattern for content type page, everything works like it should.
I have the redirect module enabled with default settings.
Comment #10
volegerHere I provided a patch and test for this bug.
Comment #11
nedjoDuplicate of #2831241: Remove old_alias related code.
Comment #12
damontgomery CreditAttribution: damontgomery commentedI'm re-opening this because it was closed based on what seems like a similar, but different issue being resolved. It seems like the other issue occurred when a pattern was set and this one occurs when it isn't.
We are using 8.6 rc1 and Path Auto 1.2.
As others have mentioned,
- Install the module and enable it for taxonomy terms at `/admin/config/search/path/settings`
- Do not set a pattern for terms
- Edit a term, you will see a `URL alias` field
- Provide an alias
- Save the term
- Reload the edit form and the field is empty
- Try to use the alias and it doesn't exist
- Go to `/admin/config/search/path` and add an alias for `taxonomy/term/123` and save
- The normal alias screen works
- Go to `/admin/config/search/path/patterns` and add a pattern for terms
- View a term edit screen and you now see the checkbox to use the default pattern
- Save the term
- Reload the term
- See that the term alias has been created with the default
- Edit the default and provide a custom alias
- Reload the term
- See that the customization is working
So, without a pattern, the UI is very misleading because the field is still there, but it's ignored. A work around is to add a pattern or to use the alias page instead.
It would be nice if the field was disabled if it isn't going to be used, or better yet, if a pattern doesn't exist, if it used Core behavior and still created the aliases as expected.
Comment #13
jacklee0410 CreditAttribution: jacklee0410 commentedI have a similar issue when doing rest export using views.
It will generate the url by pathauto for the first save node. However it won't be reflect in rest export until the second save for the node / clear cache.
FYI I'm using Drupal 8.5.x, pathouto 8.x-1.2.
Comment #14
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedThis patch includes a browser test which demonstrates the issue. The patch also includes two other tests for creating custom aliases. These tests pass. I wrote these to check if the bug is also exposed using a different working order, which appears to not be the case.
::testCustomAliasWithoutPattern()
tests setting a custom alias just after enabling Pathauto when there are no patterns yet. This also ports a portion of\Drupal\pathauto\Tests\PathautoNodeWebTest::testCustomAliasWithoutPattern()
from simpletest to phpunit, hence why I removed some code from that method. Passes.::testCustomAliasAfterAutomaticAlias()
tests setting a custom alias for an existing node that already has an automatic alias. Passes.::testCustomAliasAfterRemovingPattern()
tests setting a custom alias for an existing node that had an automatic alias, but the pattern for that is removed. This is where the bug reported in this issue gets exposed.Comment #15
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedAdded "Steps to reproduce" to the issue summary.
Comment #16
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedHere is a possible fix. This sets the pathauto state on the widget to
PathautoState::SKIP
. Not sure yet if this the right way to fix it, because I think this fix won't have effect when updating nodes via REST (which relates to the issue reported in #13 by @jacklee0410?).An other way to fix the issue would be to check on PathautoItem if the entity has a pattern and if it doesn't, ignore the pathauto state. Somehow that feels like a bad way to fix it: this would mean that setting the pathauto state explicitly to
PathautoState::CREATE
may not always result in the expected outcome: namely that the existing alias is preserved.Comment #17
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedRemoving a reference to the Feeds module in the code comments :o.
Comment #18
GiorgosKI still get this with 8.x-1.3 when trying to save a custom PATH on some nodes
if
Generate automatic URL alias
is checked the alias can be changed based on the rules set in pathauto configotherwise manually changing with
Generate automatic URL alias
unchecked does not workCan't pinpoint when/how this happens
Comment #19
fdefeyter@gmail.com CreditAttribution: fdefeyter@gmail.com commentedSame problem here
Comment #20
cobblestone.consulting CreditAttribution: cobblestone.consulting commentedI am seeing the same issue as well, with content migrated from D7 to D8. The patch fixes the issue for me. Thanks MegaChriz!
Comment #21
casey CreditAttribution: casey at SWIS commented#2881280: Pathauto prevents core path functionality fixes the same problem on another level. Not sure which is best.
Comment #22
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedAdding #2881280: Pathauto prevents core path functionality as a related issue.
Comment #23
MegaChriz CreditAttribution: MegaChriz at WebCoo commentedReroll.
Note that the code that is removed from
\Drupal\pathauto\Tests::testCustomAliasWithoutPattern()
is ported toDrupal\Tests\pathauto\Functional::testCustomAliasWithoutPattern()
(simpletest to phpunit). This was already the case in the previous patch, but I note it here again in case someone wonders why code from an existing test gets removed.Comment #24
Eric MORAND CreditAttribution: Eric MORAND as a volunteer commentedNice, not fixed after 3 years. Is this project still alive?
Comment #25
MegaChriz CreditAttribution: MegaChriz at WebCoo commented@Eric MORAND
I think the provided patch needs a detailed review. See https://www.drupal.org/patch/review
Note that since there are so many issues on drupal.org, it's quite normal for some issues to take years. There are often more issues than maintainers can handle, so they need to be selective and cannot fix everything. Issues with a good and thorough review are therefore more likely to get addressed by a maintainer.
Comment #26
BerdirCan someone test/confirm that #2946273: Alias is not generated when Pathauto widget is hidden is a duplicate? Has a very different fix.
As I committed the test conversion, this will need a reroll.
Comment #27
jasonawant@Berdir,
If I understood you correctly, you've committed the changed test. Attached is a patch w/out changed test file.
I've tested the scenario described in #2946273: Alias is not generated when Pathauto widget is hidden, and this fix solves that issue.
However while testing that, I came across another, possibly unexpected, behavior, so I created #3069519: Entity bundle with pathauto pattern and untranslated URL field creates language specific aliases.
Comment #28
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@jasonawant, he committed a test conversion, so the additional test coverage from #23 is still needed.
Rerolled that test coverage for the new
\Drupal\Tests\pathauto\Functional\PathautoNodeWebTest
test file.Comment #30
BerdirThanks everyone, committed.
Comment #32
Chris Matthews CreditAttribution: Chris Matthews commentedAny chance a Pathauto 8.x-1.5 release will ship soon? It would be great to have this in a stable release.
Comment #33
hanan alasariI Detected the urls aliases is not saved for the cloned nodes after enable clone entity module. Thank you, the patch is working for me too.