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.

Comments

das-peter created an issue. See original summary.

Status: Needs review » Needs work
wim leers’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: +Usability

And this can happen quite easily, I found: a content author modifying

data-entity-embed-display-settings="{"image_style":"","image_link":""}"

to

data-entity-embed-display-settings=""

is enough to trigger this error.

This is one of the reasons I was never a fan of @EntityEmbedDisplay plugins: these settings are not very descriptive; they're first and foremost representations of implementation details. Something like data-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.)

phenaproxima’s picture

Crediting Wim Leers for researching this.

  • phenaproxima committed 952b815 on 8.x-1.x authored by das-peter
    Issue #3010942 by das-peter, Wim Leers: More defensive handling of "data...
phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

Nice work. Committed and pushed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

alienzed’s picture

My Recent Log Entries are FULL of these errors. Is there not a better way to handle what appears to be a rather common situation?

alienzed’s picture

Update: 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?

scotthooker’s picture

I 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?

oknate’s picture

Check 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

bkosborne’s picture

I'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.

bkosborne’s picture