Problem/Motivation
If, for whatever reason, the value of "data-entity-embed-display-settings" in EntityEmbedBuilder::buildEntityEmbed() is broken - which means it isn't an array - the whole processing dies in a fatal error:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 3 passed to Drupal\entity_embed\EntityEmbedBuilder::buildEntityEmbedDisplayPlugin() must be of the type array, string given, called in /var/www/web/modules/contrib/entity_embed/src/EntityEmbedBuilder.php on line 94 in Drupal\entity_embed\EntityEmbedBuilder->buildEntityEmbedDisplayPlugin() (line 134 of modules/contrib/entity_embed/src/EntityEmbedBuilder.php). Proposed resolution
Check the format of $context['data-entity-embed-display-settings'] and if it isn't an array reset the settings and log a warning.
That way the site wont break completely and there's even a chance that it looks right while the admin has a chance to see the error in the log.
Remaining tasks
Reviews needed.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| entity_embed_more-defensive_data-entity-embed-display-settings.patch | 1.18 KB | das-peter |
Comments
Comment #3
wim leersAnd this can happen quite easily, I found: a content author modifying
to
is enough to trigger this error.
This is one of the reasons I was never a fan of
@EntityEmbedDisplayplugins: these settings are not very descriptive; they're first and foremost representations of implementation details. Something likedata-entity-view-mode="thumbnail"is something that is still meaningful, interpretable and actionable by the front end. (I know, I know, there were solid reasons, but still.)Comment #4
phenaproximaCrediting Wim Leers for researching this.
Comment #6
phenaproximaNice work. Committed and pushed!
Comment #8
alienzed commentedMy Recent Log Entries are FULL of these errors. Is there not a better way to handle what appears to be a rather common situation?
Comment #9
alienzed commentedUpdate: It appears that I get these errors even in the administration section, where no entities are embedded. It seems almost as if it is running and erring on every single page load. Is that normal?
Comment #10
scotthooker commentedI am seeing lots of these warnings with no obvious reason why data-entity-embed-display-settings would be broken. Do we have to warn on all of these errors?
Comment #11
oknateCheck that you don't have an alter hook changing this setting to a string. AFAIK, that's the only way this would happen now, see:
#3068469: Argument 3 passed to Drupal\entity_embed\EntityEmbedBuilder::buildEntityEmbedDisplayPlugin() must be of the type array, string given
Comment #12
bkosborneI'm getting a ton of these warnings too :(
I can easily reproduce it on my site as well. Just by embedding an entity using a view mode entity embed display plugin which has no settings. After embedding, the "data-entity-embed-display-settings" gets set to an empty string.
I will create a follow up issue for this.
Comment #13
bkosborneAdded follow up which includes steps to reproduce: #3077225: Logs flooded with warning messages "Invalid display settings encountered"