Hi there. I'm experiencing an issue when trying to embed an image in a node body using Entity Embed with the Entity Browser (IFrame) provided by File Entity Browser. After selecting the file and clicking the embed button, I'm being redirected to http://example.org/entity-embed/dialog/full_html/file_browser, which shows me a full page entity browser again.
When trying to reproduce the issue on my development environment, I found the following log message, but I'm not sure this is related.
PHP Fatal error: Call to a member function id() on null in /home/user/drupal8/modules/entity_embed/src/Form/EntityEmbedDialog.php on line 524, referer: http://example.org/node/10/edit
I'm running Drupal 8.2.1 with:
- Entity Embed 8.x-1.0-beta2
- Entity Browser 8.x-1.0-alpha9
- File Entity Browser 8.x-1.0-alpha1
This issue seems occur since I upgraded Drupal from 8.1.10 to 8.2.1, but I'm not 100% sure about that.
I also filed a bug with the Entity Browser project here, about an issue in Entity Browser which occurs in the same environment. I don't know if it's in anyway related, but I'll just mention it here.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | interdiff.txt | 1 KB | wim leers |
| #29 | 2820188-29.patch | 3.13 KB | wim leers |
| #29 | interdiff.txt | 1.51 KB | wim leers |
| #23 | 2820188-23.patch | 2.72 KB | rpayanm |
| #19 | 2820188-19.patch | 2.03 KB | rpayanm |
Comments
Comment #2
P44T commentedComment #3
kevinquillen commentedJust ran into this myself. Also 8.2.5.
I get
Stemming from ajax.js in the browser console when clicking on the E button in CKEditor.
Comment #4
kevinquillen commentedI cleared out the settings and re-enabled the modules.
I followed this guide:
https://www.webwash.net/manage-media-assets-drupal-8/
This time, it worked. I think my mistake was switching the selector from autocomplete to whatever the second option was... should still be handled more gracefully though IMO.
Comment #5
lpeabody commentedI ran into this as well, and what solved the issue for me was following the directions for the Create Entity Browser part (in the above mentioned guide). Specifically, setting the Display plugin to iFrame and in step 3 making sure "Auto open entity browser" is checked off.
Comment #6
dkre commentedI ran into this issue also.
Entity Browsers for Entity Embed can't use the Modal display plugin (modal inside a modal, which I think returns this ajax error).
This isn't specifically Entity Embed issues but there could possibly be a check of the entity browser's configuration to ensure the browser isn't set to modal and display a warning/error if selected?
Comment #7
P44T commentedThe redirecting issue turns out to be related to the advagg module being enabled. See https://www.drupal.org/node/2845916.
Comment #8
das-peter commentedCrossposting with #2845916: Embed module incompatible with advagg
@P44T Could you check out this advagg issue: #2833686: Issues with ajax commands / apply bugfix from core
The current advagg dev was patched and solved a pretty nasty JS caching bug.
Comment #9
nickdickinsonwildeThe redirect issue noted above is as now fixed in a stable release of AdvAgg.
This id() on null issue though... patch attached to avoid/prevent that. Specifically only list compatible entity browsers in the the select box.
Comment #11
nickdickinsonwildeTest fail noted in comment #10 is not related to patch but already present in current 8.x-1.x dev branch when testing against core 8.4.x.
Comment #12
nickdickinsonwildeComment #13
anpolimus@NickWilde I think we need to reroll your patch.
Comment #14
lamp5I solved this problem by creating a new entity browser type and using an iframe instead of a modal one.
Comment #15
anybodyPatch from #9 still works in latest .dev version. We've tested it manually. It does NOT fix the problem itself but hides incompatible entity selection widgets in the embed profiles.
Is there a chance to fix the problem and make them compatible?
Comment #16
anybody#2670016: [entity_browser] Entity Browser integration does not work with Modal displays is the same issue. We should mark one of them as duplicate and fix the key problem behind. Both offer valuable workarounds.
Comment #17
samuel.mortensonComment #18
dakwamineThis bug still occurs on dev. The provided patch needs to be updated. We need to call
$item->getDisplay()instead of$item->display:On my side, the bug occurs because the entity browser is not displaying its form in the selection step in modal type. I couldn't get to understand the design of the module so I didn't dig further. Using Iframe type circumvents the bug.
Comment #19
rpayanmre-rolled
Comment #21
maxplus commentedHi rpayanm,
just used your patch from #19 on my 8.5.4 installation with Entity Embed 8.x-1.x-dev and Entity Browser 8.x-1.5
It works, thanks!
Comment #22
liampower commentedThe patch from #19 did not work for me. After applying the patch and clearing cache, I was still getting null returned with a modal window. Using an iFrame is a workaround but not ideal.
When debugging the code I found that
$form_state->getValue(['entity_browser', 'entities', 0])->id();returns null, this is because the value of $form_state->getValue(['entity_browser', 'entities']) is an empty array.
Comment #23
rpayanm@LiamPower I added a condition to check empty arrays.
Comment #24
rpayanmComment #26
codeyourdream commented@rpayanm
The AJAX request still doesn't work, but it shows different errors now:
TypeError: Argument 1 passed to Drupal\Core\Form\FormState::setError() must be of the type array, null given, called in web/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php on line 559 in Drupal\Core\Form\FormState->setError() (line 1093 of web/core/lib/Drupal/Core/Form/FormState.php) #0 web/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php(559): Drupal\Core\Form\FormState->setError(NULL, Object(Drupal\Core\StringTranslation\TranslatableMarkup)) #1FYI:
$form_state->hasValue(['entity_browser', 'entities']) is TRUE
(count($form_state->getValue(['entity_browser', 'entities'])) > 0) is FALSE
It seems that the problem is that the first branch of if is for the case when entity browser is enabled, and the second is for the case when the user presses the "Next" button (entity browser is not enabled). But the first branch never checks that the browser values are empty.
As a result, clicking "Select entities" validates form and executes submit callback (both incorrect).
Comment #27
wim leersOnce again involves
entity_browser; updated title accordingly.With 32 followers, this is one of the issues in
entity_embedthat's impacting the most people. Bumping in priority.Comment #28
wim leers#6:
#16 says that this is the same issue as #2670016: [entity_browser] Entity Browser integration does not work with Modal displays. This appears to be true.
entity_embedmaintainer @slashrsm commented at #2670016-2: [entity_browser] Entity Browser integration does not work with Modal displays:… which happens to be exactly what #9 does.
Finally, @a-fro wrote at #2670016-17: [entity_browser] Entity Browser integration does not work with Modal displays:
Given that @marcoscano's expertise in the area of Media in D8, and the original advice of one of the maintainers, I think it's clear: we should just move forward with the patch here.
Besides, modal-in-modal is terrible UX anyway.
Comment #29
wim leersTurns out @dawehner opened a similar issue: #2904091: [entity_browser] Filter out incompatible entity browsers on the configuration form.
But he points out that not alone does the
modaldisplay not work, but neither doesstandalone. I merged his patch into this one.Comment #30
wim leersAlso, lol, this shows that even in HEAD there's explicit documentation saying this doesn't work 🙈 So much pain could've been prevented by not just having this there as text…
Comment #32
wim leersComment #35
wim leers@phenaproxima pointed out that there's one superfluous sentence. Removing that upon commit.