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

  1. Create a content type.
  2. Create a pattern which applies to this content type.
  3. Create a node with an automatic alias.
  4. Remove the pattern.
  5. 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 to PathautoState::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's postSave() 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.

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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sukanya.ramakrishnan created an issue. See original summary.

sukanya.ramakrishnan’s picture

Issue summary: View changes
sukanya.ramakrishnan’s picture

Priority: Normal » Major
esclapes’s picture

Title: URL Alias not saved on node » URL Alias not saving in some cases
FileSize
5.64 KB
5.62 KB

I 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:

'225', '/taxonomy/term/19', '/recerca', 'ca'
'227', '/taxonomy/term/54', '/test-term/test', 'ca'

The recerca term was imported without alias, and later updated diabling pahauto, and cannot be changed once pathauto is enabled again. The test-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.

esclapes’s picture

Category: Support request » Bug report
Priority: Major » Normal
Berdir’s picture

I 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..

esclapes’s picture

Status: Active » Closed (cannot reproduce)

Thanks 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.

Beanjammin’s picture

Status: Closed (cannot reproduce) » Active

I 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.

mike.vindicate’s picture

I have the same issue.

Step to reproduce:

  • Create content type page.
  • Add pattern for content type page.
  • Save some nodes with automated alias.
  • Remove pattern for content type page.
  • Edit the nodes that previously were made with a pattern

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.

voleger’s picture

Here I provided a patch and test for this bug.

nedjo’s picture

Status: Active » Closed (duplicate)
damontgomery’s picture

Version: 8.x-1.x-dev » 8.x-1.2
Status: Closed (duplicate) » Active

I'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.

jacklee0410’s picture

I 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.

MegaChriz’s picture

This 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.

  1. ::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.
  2. ::testCustomAliasAfterAutomaticAlias() tests setting a custom alias for an existing node that already has an automatic alias. Passes.
  3. ::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.
MegaChriz’s picture

Issue summary: View changes

Added "Steps to reproduce" to the issue summary.

MegaChriz’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
7.37 KB

Here 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.

MegaChriz’s picture

Removing a reference to the Feeds module in the code comments :o.

GiorgosK’s picture

I 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 config
otherwise manually changing with Generate automatic URL alias unchecked does not work

Can't pinpoint when/how this happens

fdefeyter@gmail.com’s picture

Same problem here

cobblestone.consulting’s picture

I am seeing the same issue as well, with content migrated from D7 to D8. The patch fixes the issue for me. Thanks MegaChriz!

casey’s picture

#2881280: Pathauto prevents core path functionality fixes the same problem on another level. Not sure which is best.

MegaChriz’s picture

MegaChriz’s picture

Reroll.

Note that the code that is removed from \Drupal\pathauto\Tests::testCustomAliasWithoutPattern() is ported to Drupal\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.

Eric MORAND’s picture

Nice, not fixed after 3 years. Is this project still alive?

MegaChriz’s picture

@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.

Berdir’s picture

Status: Needs review » Needs work

Can 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.

jasonawant’s picture

@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.

amateescu’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community
FileSize
3.68 KB
4.48 KB

@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.

The last submitted patch, 28: 2756703-28-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone, committed.

  • Berdir committed 1b3a1c9 on 8.x-1.x authored by amateescu
    Issue #2756703 by MegaChriz, amateescu, jasonawant, esclapes: URL Alias...
Chris Matthews’s picture

Any chance a Pathauto 8.x-1.5 release will ship soon? It would be great to have this in a stable release.

hanan alasari’s picture

I 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.

Status: Fixed » Closed (fixed)

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