For some reason, pattern is not processed on first save on new node. Only after re-editing and saving node correct path is generated.
This also triggers redirect to generate new 301 redirect for original path (the one generated after first save) at this point which I have to manually delete as it is not needed (original path is not valid).
In this case I was using pattern for book pages like this:
/books/[node:book:parents:join-path]/[node:title]
After adding and saving new book page pattern was ignored. Only after going into edit/save it was generated properly.
As I remember this behavior was not present in the past and may be related to latest update of pathauto.
This is Drupal 8.4.5 installation, custom bootstrap theme.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | pathauto-revert-2950701-16.patch | 2.21 KB | berdir |
| #13 | pathauto-revert-2950701-13.patch | 1.74 KB | berdir |
Comments
Comment #2
kapetan commentedComment #3
kapetan commentedThe error generated in logs regarding above problem is:
Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 227 of ...\core\lib\Drupal\Core\Entity\EntityStorageBase.php)
and comes from:
PathautoGenerator.php(194): Drupal\Core\Utility\Token->replace('/docs/[node:boo...', Array, Array, Object(Drupal\Core\Render\BubbleableMetadata)) #11
Pattern is: /books/[node:book:parents:join-path]/[node:title]
Problem is present only when adding new book node. After saving node this error is logged and appropriate alias is not generated.
Only after editing same node and saving it node alias is properly generated.
Comment #4
berdirI'm pretty sure that like other things, book tokens are not available when a node is saved the first time, it might also not be up to date when changing the book information.
Those book tokens are defined in token.module I think there is nothing that can be done about it in pathauto. We did a relatively complex change to make this work for menu links, we will need to investigate what needs to happen to make book tokens work too.
I'm moving this to the correct project.
Comment #5
kapetan commentedThe strange thing is that this worked just fine before upgrading from 8.4.5 to 8.5
Comment #6
berdirHm, your initial issue comment says "This is Drupal 8.4.5 installation, custom bootstrap theme." ?
Comment #7
berdirOne thing you could test is if the pathauto 1.1 update broke this and if it still works with Pathauto 1.0.
Comment #8
kapetan commentedSorry, you are right, I remember this working with 8.4.x (I'm not sure which of 8.4.x minor releases) and this indeed could be related to latest pathauto release and not to drupal core version. Issue was created just days after pathauto 1.1 release. I'll revert to previous version of pathauto and report the results.
Comment #9
kapetan commentedOk, I can now confirm that this was broken in Pathauto 1.1. Works just fine and as expected with 1.0 version.
Comment #10
kapetan commentedMoving back to Pathauto project since the issue is obviously related to latest release of Pathauto and not Token.
Comment #11
kris77 commentedI have the same issue with Pathauto 1.1 as #3
Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 227 of C:\inetpub\wwwroot\sites\sofpro.com\core\lib\Drupal\Core\Entity\EntityStorageBase.php)
Problem is present only when adding new book node. After saving node this error is logged and appropriate alias is not generated.
Only after editing same node and saving it node alias is properly generated.
Comment #12
daniel korteI had the same issue and reverted to the 1.0 version to fix it.
Comment #13
berdirI suppose this was caused by the following change that was part of #2945734: Fix automated test failures in 8.x-1.x. I guess that changed the execution order. Can you check if this fixes it for you?
I'm happy to commit that, would be helpful if someone could write some tests during a DrupalCon sprint or so, so that your use cases won't get broken again in the future.
Comment #14
joshuamiI have a similar issue with a Group dependency. (https://www.drupal.org/project/group/issues/2960181) This patch does not address that issue, but there is a similarity in that both have a "parent" entity relationship that is not loading as a part of the initial path alias pattern.
If the patch fixes the issue for the original book-related dependency, I'll open a new issue that is groups specific. Though I am not sure whether it belongs in Token, Pathauto, or Group just yet.
Comment #15
kapetan commentedI reverted back to 1.0 and forgot about this issue.
Anyway, I've just tested #13 patch on 1.1 and I can confirm that the issue is now resolved as pathauto pattern is now correctly generated on first node save.
Comment #16
berdirAlso removed the delete call()
Comment #18
berdirCommitted.
Comment #19
hlopes commented@Berdir, why do you use the updateEntityAlias method on the hook_entity_insert instead of createEntityAlias method?
Comment #20
berdirThis issue was just a revert to how it was before I changed it. Please open a new issue if you think something is wrong.