Problem/Motivation
Since upgrading to Drupal 8.7.0 and 8.7.1 from 8.6.15, a server error is caused when User "field" tokens are used.
There is no PHP error information, the page will load for a few seconds then just timeout, however after some intense debugging I've identified that the issue has something to do with when \Drupal\Core\Entity\Entity\EntityViewDisplay::build is called, which is called in \Drupal\Core\Entity\EntityViewBuilder::viewField, which is called in \Drupal\Core\Field\FieldItemList::view, which is called in token.tokens.inc at line 1626.
This issue comes to light when using the Real Name (realname) module and entering some User Field tokens to use as the User's display name. When Real Name asks Drupal's Token API to generate the value from the token string, the hook function field_tokens in token.tokens.inc is called and this problem appears.
This issue only seems to happen when using User "field" tokens [user:field_*], whereas tokens such as [user:account-name] and [user:roles] seem unaffected.
Comments
Comment #2
berdirThis is likely either a timeout or an out of memory issue? Are you using layout builder? That has some pretty serious performance issues.
One workaround is to not use the [user:field_something] tokens but use [user:field_something:value], that should be much more efficient because you access the raw value, the first will actually *render* that field into HTML and then strip the HTML again.
Comment #3
aaronmchaleInitially there was an indication of memory issues, but after increasing the memory limit the issue persisted but those indications went away. It's basically like something has caused PHP to stop processing the request and Nginx returns a 502 status code with no indication as to why.
Layout Builder is in use on the site but not enabled for the User Entity.
Using the raw value tokens actually seems to have worked, so technically speaking the immediate issue is resolved because we only need the raw values anyway. However, I'm sure there is some underlying issue here, because this only surfaced with Drupal 8.7, and after downgrading to 8.6 then back to 8.7, repeating a few times, I was able to confirm for sure that something has changed in 8.7 to cause this.
Thanks
-Aaron
Comment #4
berdirIt's possible that layout builder adds that overhead even if it is not enabled for a certain entity type.
Agree it's an issue, but I'm pretty sure there's nothing that token module can do about it, except maybe improve documentation that you should almost always use the property/value tokens.
Closing this as a duplicate of #3054042: Views performance regression related to renders, that was reported as a views issue but it's the same API.
Comment #5
aaronmchaleAgreed, happy to close in favour of related issue, if it turns out that LB isn't the root cause we can always repurpose this one. I might do some testing at some point, but after all the effort I've put into this one I'm just happy to have a resolution to the immediate issue.