Using the media browser with entity embed produces the following error:

Notice: Undefined index: data-entity-embed-display-settings in Drupal\entity_embed\Form\EntityEmbedDialog->validateEmbedStep() (line 578 of entity_embed/src/Form/EntityEmbedDialog.php)

You can see this error and the steps to reproduce here:
https://travis-ci.org/acquia/lightning/jobs/153005688#L1303

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dane Powell created an issue. See original summary.

slashrsm’s picture

Project: Entity Embed » Lightning
Issue tags: +D8Media

Recently we changed the name of the attribute: #2760801: Rename data-entity-embed-settings attribute.

I see that Lightning is hard-coding some settings in lightning_media_form_entity_embed_dialog_alter(). I suspect that this is where error comes from.

phenaproxima’s picture

I can't reproduce this on Lightning 8.x-1.x, unfortunately...I followed the steps in the failing test exactly, but no dice.

balsama’s picture

We can definitely reproduce this. It looks like a little more than fixing the hard-coded settings, but that's the crux. Thanks slashrsm.

phenaproxima’s picture

Title: Undefined index error when opening the media browser » EntityEmbedDialog assumes that display settings are always presented to the user
Project: Lightning » Entity Embed

I have traced the problem, and it's not actually Lightning's fault. (I know this partially because I traced it, and partially because I completely disabled the form_alter hook that @slashrsm mentioned and the problem still occurred.)

The problem is that it's very possible for nothing to be present in the attributes section of the Entity Embed dialog form. (In Lightning's case, it's because only one view mode is allowed for the media_browser embed button, so the select list for picking a view mode is never displayed.) The trouble is in EntityEmbedDialog::submitEmbedStep() -- line 735 -- which assumes that attributes[data-entity-embed-display-settings] is always present in the form (it uses the ?: operator, which emits an undefined index notice). It needs to do an isset() check or something similar.

phenaproxima’s picture

Title: EntityEmbedDialog assumes that display settings are always presented to the user » EntityEmbedDialog causes undefined index notice if no embed display settings are presented to the user
dagmar’s picture

Status: Active » Needs review
FileSize
807 bytes

I saw this error in my logs. This works for me.

Dave Reid’s picture

Status: Needs review » Needs work
+++ b/src/Form/EntityEmbedDialog.php
@@ -575,7 +575,7 @@ class EntityEmbedDialog extends FormBase {
+    $plugin_settings = !empty($entity_element['data-entity-embed-display-settings']) ?: array();

I don't think the ?: syntax works with a function call which returns a boolean, because we want to actually return the value.

dagmar’s picture

Status: Needs work » Needs review
FileSize
863 bytes

Oh, right. Here is a new version.

Status: Needs review » Needs work

The last submitted patch, 9: entity_embed-display-settings-warning-2786493-9.patch, failed testing.

dagmar’s picture

Status: Needs work » Needs review
FileSize
862 bytes
slashrsm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

  • slashrsm committed 20101ec on 8.x-1.x authored by dagmar
    Issue #2786493 by dagmar, phenaproxima, slashrsm, Dave Reid:...
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you all. Assuming Lightning will do its stuff in a separate issue so closing.

Status: Fixed » Closed (fixed)

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