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.
Comment | File | Size | Author |
---|---|---|---|
#25 | 2881280-25.patch | 5.31 KB | vijaycs85 |
| |||
#25 | 2881280-25-test-only.patch | 4.58 KB | vijaycs85 |
|
Comments
Comment #2
merauluka CreditAttribution: merauluka at Mediacurrent commentedComment #3
merauluka CreditAttribution: merauluka at Mediacurrent commentedAttached for consideration is a patch that appears to resolve this issue.
Comment #4
merauluka CreditAttribution: merauluka at Mediacurrent commentedChanging issue status to "Needs Review" to kick off testing.
Comment #5
labboy0276 CreditAttribution: labboy0276 at Tandem commentedI can confirm this works.
Comment #6
BerdirThanks 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?
Comment #7
labboy0276 CreditAttribution: labboy0276 commentedThe 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.
Comment #8
LaurensV CreditAttribution: LaurensV commentedI am having the same issues with normal nodes.. Url alias is not saved when I don't set a pattern for nodes.
Comment #9
merauluka CreditAttribution: merauluka at Mediacurrent commented@LaurensV Was your issue resolved by using the patch in #3?
#2881280-3: Pathauto prevents core path functionality
Comment #10
martinpe CreditAttribution: martinpe commented+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.
Comment #11
lukas.fischer CreditAttribution: lukas.fischer commentedYes, it's major/critical. Thanks for the fix!
Comment #12
nicrodgersThis 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!Comment #13
rferguson CreditAttribution: rferguson commentednicrodgers,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
Comment #14
nicrodgers@rferguson, that's right. I initially thought this patch fixed it, but unfortunately it doesn't.
Comment #15
chOP CreditAttribution: chOP commented@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.
Comment #16
BerdirSome other recent fixes might have solved the problems here, please update this if you still have a problem with the latest dev version.
Comment #17
Sunil S. CreditAttribution: Sunil S. commentedHi 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.
Comment #18
erichomanchuk CreditAttribution: erichomanchuk commentedI 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.
Comment #19
BerdirWhich 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.
Comment #20
GrimreaperHello,
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
Comment #21
Sarenc CreditAttribution: Sarenc commentedPatch worked for me.
Drupal 8.5.4 and Pathauto 8.x-1.2
Comment #22
Nikolay Borisov CreditAttribution: Nikolay Borisov commentedIn 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 :)
Comment #23
5n00py CreditAttribution: 5n00py as a volunteer commentedJust tested on lastest dev release of pathauto and core 8.5.6.
Bug still exists.
Patch fixed issue correctly.
Comment #24
deviantintegral CreditAttribution: deviantintegral at Lullabot commentedPatch works for me, and on review makes sense. I'd set as RTBC but it still needs test coverage.
Comment #25
vijaycs85Adding tests...
Comment #26
vijaycs85It'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?
Comment #27
Chris CharltonThis 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)
Comment #28
skylord CreditAttribution: skylord commentedPatch from #25 fixes this issue for me. Thanks!
Comment #29
vijaycs85Wonder if this is fixed as part of #2950701: Pathauto pattern is not applied on first node save.
Comment #30
LupusGr3y CreditAttribution: LupusGr3y at Novicell commentedThis issue has not been fixed. We are still experiencing problem and require the patch from #25 in order to fix it.
Comment #31
akbuje CreditAttribution: akbuje as a volunteer commentedAfter 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.
Comment #32
jasonawantThis 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.
Comment #33
RmrJmrGrl CreditAttribution: RmrJmrGrl commentedIs this patch going to be rolled into the module release?
Comment #34
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedClosing as a duplicate of #2756703: URL Alias not saving in some cases.