When an entity whose path is not managed by pathauto's patterns is give a manual URL alias, the alias is not saved.

Specifically I'm seeing this with taxonomy terms where there isn't a pattern declared for the vocabulary. On the same site I see that URL aliases are allowed to be manually set on a taxonomy term when the "Generate automatic URL alias" checkbox is deselected. This the expected Pathauto behavior.

However, on terms that aren't using Pathauto patterns, the default URL Alias field appears (as expected) without the "Generate automatic URL alias" field (again, this is expected). But when I debugged the code, it gets to this function in PathautoItem.php:

  public function postSave($update) {
    // Only allow the parent implementation to act if pathauto will not create
    // an alias.
    if ($this->pathauto == PathautoState::SKIP) {

And it never passes the conditional. So the manual alias is sent to the pattern system which will never give a URL for the entity. This results in the URL that was entered being lost and never saved.

Proposed resolution

Update Pathauto to allow for core's path functionality to work when a pattern is not set for and entity bundle.

Members fund testing for the Drupal project. Drupal Association Learn more


merauluka created an issue. See original summary.

merauluka’s picture

Issue summary: View changes
merauluka’s picture

Attached for consideration is a patch that appears to resolve this issue.

merauluka’s picture

Issue summary: View changes
Status: Active » Needs review

Changing issue status to "Needs Review" to kick off testing.

labboy0276’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm this works.

Berdir’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Thanks for the bug report and patch. I'm not sure I fully understand this. Seems like more bug reports should have been provided by this if this would really happen like that.

The pathauto property should default to skip if no pattern is defined, see \Drupal\pathauto\PathautoState::getValue(). We also have an explict test for this, because we did fix a bug like this a while ago: \Drupal\pathauto\Tests\PathautoNodeWebTest::testCustomAliasWithoutPattern().

Maybe you are using a core patch or contrib module that conflicts with this somehow?

Needs a failing test to show how this happens exactly, maybe you can figure out something and extend the test there?

labboy0276’s picture

The issue is when I tried to save a taxonomy term alias it would not save. I stripped my instance down to just core and pathauto and got the same result. With this patch, you can now save aliases on all entities. Before using it, I could not.

Also there are a couple issues in this queue that are similar to this one in nature.

LaurensV’s picture

I am having the same issues with normal nodes.. Url alias is not saved when I don't set a pattern for nodes.

merauluka’s picture

@LaurensV Was your issue resolved by using the patch in #3?

#2881280-3: Pathauto prevents core path functionality