Closed (fixed)
Project:
Entity Embed
Version:
8.x-1.x-dev
Component:
Code
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Jul 2019 at 17:58 UTC
Updated:
8 Apr 2026 at 16:35 UTC
Jump to comment: Most recent, Most recent file

Comments
Comment #2
johnlutzComment #3
wim leersThis code has been in Entity Embed since 2016. I'm surprised this is only coming up now.
Also, probably I'm missing something, but I don't see how the patch changes anything related to array access? I don't see how this could fix this notice? Could you enlighten me? :)
Comment #4
wim leersComment #5
swentel commentedI've had a similar error, but during rendering. The problem is that data-entity-embed-display-settings might be an array and this can't be rendered in twig, the string should be jsonencoded again before passing on into #attributes again.
see line https://git.drupalcode.org/project/entity_embed/blob/8.x-1.x/src/EntityE...
commenting out that line fixes the notice during rendering
Comment #6
drcolossos commentedWe have the same issue:
Looks like a problem that the "data-entity-embed-display-settings" property inside the FormState::values() does not get properly unset if there are no properties left. MediaImageDecorator::submitConfigurationForm() unsets the "title" or "alt" but not the containing "data-entity-embed-display-settings" afterwards if there are no properies left inisde the array. So it will be used in the code that the patch mentions.
I tried to figure out why this happened but could not find what changed.
*update* after looking in the logs, the problem persists for quite some time now. We only spotted it since we updated our development configuration to output devel messages more verbose on notices/errors
Comment #7
oknateThere seems to be a difference of opinion as to what is the cause of this. Can people share their entity embed button configs, so I that the bug is reproducable?
Comment #8
drcolossos commentedSure
Comment #9
weynhamzMight be related https://www.drupal.org/node/2917132 and https://www.drupal.org/project/entity_embed/issues/3021505.
Below is the data structure of `data-entity-embed-display-settings` that causes the 'Notice', `AttributeArray::__toSting()` expects an indexed array, but below is an associative array.
Comment #10
weynhamzMay be just simply json_encode it?
Comment #12
sun-fire commentedHi!
I had the same issue, and after some debugging I found, than some components of $values['attributes'] can be arrays. In this case current logic of filtering for empty attributes fails with error and upload provess fails also with ajax error (this error is available in the browser's console only, and not available in the database log.
So, I created a patch, which allows to filter empty attributes, with checking of sub-arrays (during debugging I did not find more than one child sub-arrays), and replaced original array_filter() logic with iteration, because with array_filter() we are unable to return the changed values in subarrays: please see https://www.php.net/manual/en/function.array-filter.php
The iteration works little slower rather than array_filter() but it allows us to filter possible combinations of attributes and not fails with error.
So, please check the patch in attach.
Comment #13
sun-fire commentedComment #14
sun-fire commentedFixed path in patch structure
Comment #15
drcolossos commentedI think this can be simplyfied
is not necessary, since its the default from the iteration anyways
the cast to bool should not be necessary since it returns a number so the condition should evaluate properly
Comment #16
alison(I've got this warning message, too.)
"Location" of the message, in case it helps, is:
/entity-embed/dialog/filtered_html/image_embed?_wrapper_format=drupal_ajax&_wrapper_format=drupal_modal&ajax_form=1In response to #7, here's my embed button:
........."Just in case" it's helpful, here's the text format in which I'm using an embed button:
Comment #17
oknateI wasn't able to recreate the warning displaying in the logs or to the screen or causing ajax errors, but I was able to see that the code here fails with an empty array;
This would lead to the array to string conversion here:
return (bool) mb_strlen((string) $value);I came up with my own solution to fix this:
I tried out the other solutions, but I had issues with each:
Regarding #2, this results in $values["attributes"]["data-entity-embed-display-settings"] = '[]';
This doesn't work because it won't get filtered out by
return (bool) mb_strlen((string) $value);Regarding #9, I put a breakpoint there, and just before this code below in EntityEmbedDialog, and it hit the code in EntityEmbedDialog first with it still an array, so I don't think this fixes the problem in the dialog.
Regarding #14, the only value that could be an array is data-entity-embed-display-settings, so this solution seems overly complicated.
Comment #18
komejo commentedPatch in #17 worked for me.
Comment #19
jorgegc commentedUploading a simplified patch for review.
My suggested approach is that we catch $values['attributes']['data-entity-embed-display-settings'] in the array_filter, making the code more generic so any future empty arrays will be filtered out.
Comment #20
peterwcm commentedTested #19 and working for me. Thanks for the patch.
Comment #21
plato1123 commentedThe patch in #19 works great, thanks!
Comment #22
scoff commentedPatch #10 or a similar solution is needed.
#10 works (no more "array to string" warnings) but I'm not sure if it's useful for anything
data-entity-embed-display-settings="{"image_style":"","image_link":"","svg_render_as_image":1,"svg_attributes":{"width":"","height":""}}"
Comment #23
phenaproximaThis patch has no tests...is there any way we could add some?
EDIT: Since the bug is related to how the dialog is handling different values, I think a kernel or unit test might be sufficient here.
Comment #24
Anonymous (not verified) commented#19 works for me. thanks
Comment #25
fabiansierra5191 commented#19 works and as Phenaproxima said a kernel test should be enough.
Comment #26
alison#19 worked for me, thank you!
Comment #27
baluertlOne more confirmation of #19 eliminates the issue, thanks for sharing @jorgegc!
Comment #28
purefoxy commentedAnother confirmation of #19 eliminates the issue, thanks for sharing @jorgegc and @promes for implementing.
Drupal core: 9.1.8
Entity Embed: 1.1.0
PHP: 7.2.34 (memory limit: 128M)
Comment #30
tobiasbInterdiff patch 19 - 30:
The patch contains also the fix from #3249967: Skip test ConfigurationUiTest::testValidationWhenAdding for Drupal core 9.2 >=.
Comment #31
gregrholden commentedConfirmation #19 works. Thanks @jorgegc!
Drupal 9.2.7
Entity Embed: 8.x-1.2
PHP: 7.4.12
Comment #32
cgmonroe commentedThe patch in #30 does not apply with Entity Embed V1.3 because the extra fix in it for #3249967: Skip test ConfigurationUiTest::testValidationWhenAdding for Drupal core 9.2 >= is no longer applicable.
Attached is an updated version for 1.3 / dev. The same except there are no changes to the ConfigurationUiTest.php code and the line numbers are updated.
Comment #33
eric_a commentedManual testing seems to indicate that this issue is gone with entity_embed 1.3.
I'm guessing that #3106808: Array to string conversion notice when embedding a Media file fixed some underlying issue. Which would make this one "Closed (outdated)". Or "Closed( duplicate)".
Can others confirm?
Comment #34
phenaproximaEven if it's gone...look at that magnificent test coverage in this patch! We should add that anyway.
Comment #35
eric_a commentedWait. There are tests? Excellent.
Found them!
Attached is a patch which should contain just the tests from #32. Very curious about the current state of affairs without the actual fix from #32.
Leaving issue title as is for now.
Comment #37
neclimdulI think this makes sense. Ran into this today with 1.3 and the patch in #32 fixed it. RTBC.
Comment #38
phenaproximaEDIT: Redacted.
Comment #39
phenaproximaShould we maybe cast the result of
mb_strlen()to a bool, just for clarity's sake?Strange formatting here. Can we just have
->install(['entity_embed_test'])?Inconsistent variable naming. $EntityEmbedDialog should probably just be $entity_embed_dialog.
This construction could give us a false positive (i.e., it passes when it should fail) if there is no editorDialogSave command in $commands. We should probably add some kind of check for that.
We don't need this @see.
Do we need this line?
Comment #40
tjmoyer commentedHere's a re-roll of #32 for Drupal 9.5.2. and Entity Embed 8.x-1.3.
Comment #43
acbramley commentedRolled #32 into an MR and addressed most of the feedback in #39
Only outstanding issue is 39.4 which I'm not too sure how to handle.
Comment #44
neclimdulWorks for me. Back to RTBC?
Comment #45
phenaproximaThis should go into the 2.0.x branch first, and then potentially backported.
Comment #46
liam morlandIs something holding-up getting this committed?
Comment #47
joseph.olstadOnce someone patches this for themselves (Me, Myself and I, Us, We, Our group, Our build), they, themselves, them, those people, others quickly forget about it ever having been a problem and often do not follow up.
Comment #48
phenaproximaComment #50
phenaproximaI guess it had just fallen off the radar. Merged into 2.0.x. I can also commit this to 8.x-1.x if someone can open a separate MR (in this issue) to backport it.
Comment #51
joseph.olstadPrevious minor is passing testing, however 6 months has passed and a few new minors , now failing.
Comment #52
liam morlandThe two branches are identical. You can just do a fast-forward merge.
I doubt the test failures are because of this issue. A new issue should be opened to fix them.
(These tags can probably be deleted:
previous/3287235-automated-drupal-10/2022-10-20,previous/3287235-automated-drupal-10/2022-10-17.)Comment #53
joseph.olstadThe fix for the failures are in an RTBC issue
There's a bunch of other RTBC issues at the top of the issue queue.
Comment #54
phenaproximaHuh? How can that be true? All PHPUnit test jobs in that issue are failing...
Comment #55
joseph.olstadAh yes they are failing, my mistake. Likely more than one change introduced in the latest minor 10.5 and 11.2 at play here.
Comment #57
dave reidI was able to cleanly cherry-pick this commit to 8.x-1.x, so marking as closed.