Problem/Motivation

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) {
      parent::postSave($update);
    }
    $this->get('pathauto')->persist();
  }

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.

Steps to reproduce

1. Enable path auto module
2. Add a new pattern at /admin/config/search/path/patterns
3. Select 'Node' in type field and select one bundle. Say 'article' (assuming there are two: article and page)
4. Create a new page at node/add/page
5. Observe that there is no 'Generate automatic URL alias' checkbox.
6. Add a new page with custom alias.
7. Try to edit the page

Expected
Url Alias should persist and able to see in the node edit page

Actual:
Url Alias field is empty.

Proposed resolution

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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

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

martinpe’s picture

Priority: Normal » Major

+1 for having the same problem. Patch solves that.

Please merge the patch into the main code asap. Using custom/manual aliases is critical to some people.

lukas.fischer’s picture

Yes, it's major/critical. Thanks for the fix!

nicrodgers’s picture

This also fixes a problem we were having with workbench_moderation and content translation: editing drafts of published translations since updating to 8.4. We would constantly get the error "You can only change the URL alias for the published version of this content" even though nothing the URL alias had not changed. Thanks for the patch!

rferguson’s picture

nicrodgers,I'm guessing this doesn't fix the issue? I'm getting that as well when using content moderation in d8 on non-default language nodes

nicrodgers’s picture

@rferguson, that's right. I initially thought this patch fixed it, but unfortunately it doesn't.

chOP’s picture

@nicrodgers @rferguson

We're starting to look at this problem now of URL alias changes on unpublished content, or content that is in an draft workflow state (workbench moderation). While we don't have a fix yet, these may be of interest while we're working through it:

Seems like this validation constraint is causing pain for content moderation used with other modules too.

Berdir’s picture

Status: Needs work » Postponed (maintainer needs more info)

Some other recent fixes might have solved the problems here, please update this if you still have a problem with the latest dev version.

Sunil S.’s picture

Hi I also face one of issue that, I have a multilingual D8 site. I migrated contents from D7 site. Now what is happening, if a content have same url in both EN and let say FR language then it is not updating. e.g. I have a url www.example.com/en/expert/abc and in french version it is www.example.com/fr/expert/abc. Now, I want to update the url alias from node edit form, it is not updating. It is giving message as node updated, but it is not actually updating the url alisas. After disabling pathauto module it is working but with pathauto it is not updating.

erichomanchuk’s picture

I was experiencing an issue when using, entity clone, and cloning a node. The cloned node would not save a url alias. This patch fixed the issue.

Basically I had a node, type page, with no pathauto settings set for it. Creating a node and setting a url alias worked fine. Clone the node and try to set the url alias would not save. The only way I got it to work without the patch or uninstalling pathauto was to create a pattern for it which then automatically generated a url alias on the cloned node which then let me override the url alias disabling "Generate automatic URL alias". But I do not want to auto generate a path alias for this content type. I am using workflows as well.

Berdir’s picture

Which version? 8.x-1.1/1.2 contain some pretty big changes related to stuff like this, but there's also still another open, possibly related issue where I'm also still looking for steps to reproduce starting from a clean installation.

Grimreaper’s picture

Hello,

Thanks for the patch. I ran into this issue and it solved the problem.

I am on Drupal 8.5.3 and Pathauto 8.x-1.2

Sarenc’s picture

Patch worked for me.

Drupal 8.5.4 and Pathauto 8.x-1.2

Nikolay Borisov’s picture

In Drupal 8.5.5 I experience the same problem.
I am also using the "Quick Node Clone" so it is quite possible that it is causing the problem.

The patch #3 is fixing my problem.

Thanks :)

5n00py’s picture

Status: Postponed (maintainer needs more info) » Needs review

Just tested on lastest dev release of pathauto and core 8.5.6.
Bug still exists.

Patch fixed issue correctly.

deviantintegral’s picture

Patch works for me, and on review makes sense. I'd set as RTBC but it still needs test coverage.

vijaycs85’s picture

vijaycs85’s picture

Issue summary: View changes
Status: Needs review » Needs work

It's possible this is fixed by some other commit, but I couldn't reproduce the issue. I have updated the steps to reproduce from what I understood from issue summary. could someone still facing this issue validate and update steps please?

Chris Charlton’s picture

This has been a pain.

Comment #26 poses a good question. We should just validate/exhaust that thought.

And, as many people have pointed out that patch #3 helped with their issue. Tests passed too. (Be sure to read #26 before proceeding)

skylord’s picture

Patch from #25 fixes this issue for me. Thanks!

vijaycs85’s picture

Status: Needs review » Closed (won't fix)
LupusGr3y’s picture

This issue has not been fixed. We are still experiencing problem and require the patch from #25 in order to fix it.

akbuje’s picture

Status: Closed (won't fix) » Needs review

After trying to use pathauto with the changes in #2950701, it seems not to fix this issue.

Therefor I am still relying on the patch in #25

I hope we can get this change folded into the pathauto at some point.

Changing to needs review, to make sure that this is not fixed in #2950701 and reaffirm that the fix in #25 is actually working fine.

jasonawant’s picture

This patch allowed me to save a manual alias, but it did not allow me to delete the manual alias, once saved, from the node/term edit form.

I think this is a duplicate of #2756703: URL Alias not saving in some cases. Applying the patch from that issue allowed me to save and delete manual alias for bundles without pathauto patterns configured.

Once someone else can confirm this, then we can close this as a duplicate of that issue.

RmrJmrGrl’s picture

Is this patch going to be rolled into the module release?

amateescu’s picture

Status: Needs review » Closed (duplicate)