I have a number of content types that should only get aliases via pathauto. We've hidden the url alias widget from the form as an easy way to deny access to editing them. Unfortunately, this seems to prevent aliases from auto-generating when they're initially saved. I traced this back to the generator, which checks the pathauto state ($entity->path->pathauto != PathautoState::CREATE) and exits early. So the pathauto state is not being set to CREATE for entities that do not have the url alias field on the form.
For context, we recently updated to Drupal 8.4. I'm not sure if this is related, but the timing seems suspect - we've had no reports of this issue before the update.
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | 2946273-37.patch | 1.84 KB | amateescu |
| #37 | 2946273-37-test-only.patch | 1.38 KB | amateescu |
| #25 | pathauto_2946273-25.patch | 472 bytes | seanb |
| #23 | pathauto_2946273-23.patch | 476 bytes | cgmonroe |
| #18 | pathauto_2946273-18.patch | 1.34 KB | rbayliss |
Comments
Comment #2
berdirThere were various reports since 8.4 about strange effects. Only found time now to start looking into it. Can you check if #2945734: Fix automated test failures in 8.x-1.x is fixing this for you?
If not, a failing test would be helpful.
Comment #3
rbayliss commented@berdir - Yeah, I do think this is related. I think I actually found the solution to my issue, which was super simple. Not sure if this will help with the other 8.4 ticket or not, but it seems like it should. I'm gonna switch this over to needs review to see what testbot says, but feel free to postpone again or take this over to #2945734.
Comment #4
rbayliss commentedAh, just to give more context, the patch in #2945734: Fix automated test failures in 8.x-1.x did not solve my issue. This patch, however, did.
Comment #5
rbayliss commentedI believe this is the relevant 8.4 change that helped me get to this patch and might inform the other issue.
Comment #6
berdirAny chance you can create a failing test that shows the scenario this fixes?
Comment #8
rbayliss commentedI will give it a shot next week. It's definitely related to the URL field's presence on the form, although I'm not sure it's as simple as "when it's there it works, when it's not it doesn't." I'm ending up in ::isEmpty() with just a langcode, but I can't figure out why it's happening on some content types but not others. I really think it's related to what you're working on in #2945734: Fix automated test failures in 8.x-1.x though, because computed properties weren't staying set until I fixed the isEmpty() check.
Comment #9
rbayliss commentedHuh, ok. On closer review, it looks like this is reliably reproducible on a bare install using the following steps:
1. Enable the paragraphs module and create 2 paragraph types.
2. Create a content type and add a new Paragraph field that's allowed to reference either of the two types.
3. Hide the alias field for the content type from the form.
4. Create a new node of that type, **making sure to add a paragraph of either type**.
5. Observe that no alias is created.
I believe this is triggered by the ajax action prior to final submission. The alias works just fine if you either don't use ajax during the creation of the content, or have the path field exposed on the form. I'm not sure how to write an effective test for this. Any suggestions?
Comment #10
cgmonroe commentedI had a similar problem using the Feeds module. I distilled it down to the following problem case where the path is not defined in a node. Here's a some code that fails when run in the Dev execute PhP page.
The odd thing is that the ksm call is required to make it fail.
As the report says, pathauto does not generate the URL because $node->path->pathauto is NULL when the the updateEntityAlias method checks if the create flag has been set ( ~ line 306 ).
Seems like the "skip if pathauto processing is disabled" code should include a test if an entity is new and pathauto is NULL that allow the process to continue.
Comment #11
rbayliss commentedAh! Good call! Accessing any of the path properties prior to save simulates the error I'm describing. Knowing that, here's a test that should fail.
Comment #12
rbayliss commentedAnd a patch including both the test and the fix.
Comment #14
berdirThose kind of problems are exactly what my changes in #2945734: Fix automated test failures in 8.x-1.x should solve. And they do, I verified that this test change is passing when combined with those changes.
However, I would prefer if it would be in \Drupal\Tests\pathauto\Kernel\PathautoKernelTest, possibly in an existing method. Can you do that as a test-only patch and a combined patch with my changes? Then we can commit that and I really think that most of the problems that people are reporting are fixed then.
Comment #16
rbayliss commentedSure, here you go. FWIW, I did try the patch in #2945734: Fix automated test failures in 8.x-1.x, and it doesn't solve the issue for me without this additional isEmpty() change.
Comment #18
rbayliss commentedFix typo (lancode -> langcode). Thanks Moshe!
Comment #20
moshe weitzman commentedComment #21
cgmonroe commented+1 on Reviewed.
With this patch nodes with an pathauto pattern get created with the aliases and not /node/####.
Comment #22
berdirAs I suggested above, I moved the test to #2945734: Fix automated test failures in 8.x-1.x and committed it as part of that (with issue credit).
I do believe you that it doesn't fix your problem, but it would be great to have a test that actually covers that scenario. We could for example try to write an actual JS test that triggers an ajax operation (One option would be to do a file upload or maybe something as simple as a multi-value field with an add-another button?).
@cgmonroe: I would expect that your issue is resolved with the patch that I now committed.
Comment #23
cgmonroe commentedFYI - Creating nodes via Feeds (or programatically) still fails after updating pathauto to the latest Dev. I still needed to patch the PathautoItem.isEmpty() method with the patch above.
I think part of this is Drupal core 8.4 vs 8.5. The testCreateNodeWhileAccessingPath is passing in the Drupal 8.5 test environment. However, if I run the test code in a Dev PhP window on my 8.4 site, it fails to create a node with an alias.
Anyway, attached is the same patch as #18 without the test which you have already committed. It applies cleanly to the new dev code.
Comment #24
daniel korte#23 solves my issue of path aliases not being created on node creation with 8.x-1.1.Never mind. This is no longer working. May be related to #2950701: Pathauto pattern is not applied on first node save.
Comment #25
seanbRerolled the patch since I had some issues applying the patch in #23.
Comment #26
berdir@seanB: Do you have a use case where this is needed? We still don't have a failing tests on 8.4.5+ that needs this change.
Comment #27
seanb@Berdir I will have to get back to you on that, was just fixing a build and was not involved in the decision to use this patch. My collegue is not working rest of the week so I'll let you know when I had the chance to talk to him!
Comment #28
jrsouth commentedI can confirm that as of pathauto 8.x-1.2 within Drupal 8.5.2, new content nodes created via the GUI still do not have a pathauto pattern applied if the "URL Alias" form element is disabled within that content type's form display settings.
(The correct pathauto pattern is applied after the second "save".)
I'm not sure how to go about creating a test, but I'm happy to provide whatever info I can.
In the meantime, the patch in #25 has fixed the issue. (Exposing the URL Alias widget is not a viable option for us.)
Comment #29
JvE commentedComment #30
andres.torres commentedComment #31
DJMyles commentedI can also confirm that as of pathauto 8.x-1.3 within Drupal 8.6.4, new nodes created via the GUI still do not have a pathauto pattern applied if the "URL Alias" form element is disabled within that content type's form display settings.
The pathauto pattern is only applied after a resave.
Can confirm patch #25 has fixed the issue.
Comment #32
JvE commentedComment #33
MikeHauden commentedConfirm the #25 patch still works applied to 1.4 on core 8.7.3.
Comment #34
cgmonroe commentedEnabled testing on current patch.
Comment #35
honza pobořil commented#25 works with core 8.7.5 and Pathauto 1.4.0
Comment #36
frobLooks like the patch still needs failing tests that this patch can fix as per @Berdir in #2946273-26: Alias is not generated when Pathauto widget is hidden
Comment #37
amateescu commentedHere's a test for this. Note that #2756703: URL Alias not saving in some cases does not fix this issue.
Comment #40
berdirThanks.
Comment #41
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.