PHP error

TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 144 of /core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php)

Steps to reproduce

Use media library in CKeditor, doesn't matter if it is 5 or old one.

  1. Click on add media button in CKeditor
  2. Ensure that you have some filters on your media popup
  3. Select 1 item from list
  4. Filter results to hide somehow that item
  5. Click on insert selected

So your popup will not refresh with error message but you'll get that PHP error in backend.

Issue fork drupal-3340973

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ion.macaria created an issue. See original summary.

ion.macaria’s picture

Status: Active » Needs review
StatusFileSize
new872 bytes

Tested patch on Drupal 9.5.x and Drupal 10.1.x

ion.macaria’s picture

Issue summary: View changes
ion.macaria’s picture

Issue summary: View changes
cilefen’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: -media library +Needs steps to reproduce

We require some steps to reproduce. A bug like this would show in automated tests, so it must be an untested feature.

bhogue’s picture

I get this error, but only after I've updated my site and modules from 9.4.x to 9.5.x.

If I go to a node edit page for a node that has a Media entity and click "Add media," nothing happens. No error is presented, even though I have seen Ajax errors generate error messages in the admin UI. An Ajax error does show up in the console, but it's very unhelpful and simply points to line 448 of ajax.js, which is inside this function: Drupal.Ajax.prototype.error = function (xmlhttprequest, uri, customMessage) {

Then, in the dblog, the error is as the original poster said:

TypeError: Drupal\Core\Render\Element::children(): Argument #1 ($elements) must be of type array, null given, called in /var/www/html/web/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php on line 957 in Drupal\Core\Render\Element::children() (line 72 of /var/www/html/web/core/lib/Drupal/Core/Render/Element.php)

I have tried uninstalling several Media-related modules like media_library_edit and dropzonejs, and I also toggled off JS aggregation, none of which has helped.

The patch above does not alleviate the problem either, unfortunately.

bhogue’s picture

At least in my case, I was getting the error because I applied an unrelated patch (https://www.drupal.org/project/drupal/issues/2784233) to add some view functionality and then removed it, but some of the patched config was left behind.

pacproduct’s picture

Hi everyone :)
I'd like to add my experience on this matter, for info.

I was facing the initial issue as described by @ion.macaria, (with Drupal 10.0.9):
TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 134 of [...]/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php).

I was facing the issue when trying to add a custom block containing a media field: When clicking button "Insert selected", nothing was happening on screen, an HTTP error 500 was thrown in the console and the message above was saved in the watchdog.

Patch #2 worked around the error message, but did not solve the behavior in my case, no media was attached and the following error was displayed on screen: "No items selected."

More generally in fact, trying to add images via the dedicated page (/media/add/image) didn't work for me either, as submitting the form was raising an error message: "Image field is required." although I had selected a file. And then I noticed that I also had 413 HTTP errors just after selecting the picture file to upload:
Turns out the issue was with NGinx which wasn't configured to accept large requests, and I was trying to upload pictures larger than 2MB.

Maybe we could argue that Media should be able to handle such errors more gracefully, but (in my case at least) the issue was not directly related to Drupal in the end. YMMV.
Reconfiguring Nginx to accept larger requests solved the problem for me.

jurgenhaas’s picture

We're facing the same problem every now and then, but we haven't ever been able to reproduce this. The proposed patch solved the issue, however it could be simplified by providing an empty array as the default value to getValue:

$selected = array_filter($form_state->getValue($this->options['id'], []));

In terms of reproducing this, here is a stack trace that we captured when it happened last time:

TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (Zeile 134 in /var/www/html/web/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php)

#0 /var/www/html/web/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php(134): array_filter()
#1 /var/www/html/web/core/modules/views/src/Form/ViewsFormMainForm.php(160): Drupal\media_library\Plugin\views\field\MediaLibrarySelectForm->viewsFormValidate()
#2 /var/www/html/web/core/modules/views/src/Form/ViewsForm.php(187): Drupal\views\Form\ViewsFormMainForm->validateForm()
#3 [internal function]: Drupal\views\Form\ViewsForm->validateForm()
#4 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array()
#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(275): Drupal\Core\Form\FormValidator->executeValidateHandlers()
#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm()
#7 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm()
#8 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm()
#9 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm()
#10 /var/www/html/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2257): Drupal\Core\Form\FormBuilder->getForm()
#11 [internal function]: Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender()
#12 /var/www/html/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array()
#13 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\Core\Render\Renderer->doTrustedCallback()
#14 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\Core\Render\Renderer->doCallback()
#15 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(446): Drupal\Core\Render\Renderer->doRender()
#16 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(446): Drupal\Core\Render\Renderer->doRender()
#17 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
#18 /var/www/html/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\Core\Render\Renderer->render()
#19 /data/default/public/php/twig/6464247d8699b_media-library-wrapper.htm_64Qt6dm_K6TuoM9wWjBIUf2v4/GrNXcCi0Wo6rsSK-g5BY2yA2GsqjdrSng-IEDDy6yPs.php(48): Drupal\Core\Template\TwigExtension->escapeFilter()
#20 /var/www/html/vendor/twig/twig/src/Template.php(405): __TwigTemplate_a0016fa4ab1cdaac37991db0b1750750->doDisplay()
#21 /var/www/html/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#22 /var/www/html/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
#23 /var/www/html/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render()
#24 /var/www/html/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
#25 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
#26 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
#27 /var/www/html/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(242): Drupal\Core\Render\Renderer->render()
#28 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#29 /var/www/html/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(243): Drupal\Core\Render\Renderer->executeInRenderContext()
#30 /var/www/html/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
#31 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
#32 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
#33 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#34 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(174): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#35 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#36 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#37 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#38 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#39 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#40 /var/www/html/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#41 /var/www/html/web/modules/contrib/crowdsec/src/Middleware.php(82): Drupal\ban\BanMiddleware->handle()
#42 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\crowdsec\Middleware->handle()
#43 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#44 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#45 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle()
#46 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#47 {main}

Other than that, this could be RTBC from my POV.

thidd’s picture

In my case, there is some issue with public folder permission.
I tried to upload a new media in media adding form page, then saw the real problem -
the upload directory public://2023-07 for the file field field_media_file could not be created or is not accessible....
Then grant 755 for sites//files will fix.

chris matthews’s picture

Assigned: ion.macaria » Unassigned
Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Clear steps to reproduce have not been provided so closing this issue accordingly. If steps to reproduce can be provided then please feel free to reopen.

jurgenhaas’s picture

I'm uncertain about closing it for the given reason. A couple of people reported the issue, and all of us tried without luck to make it reproducible. However, providing a default for a method call like $form_state->getValue($this->options['id'], []) should be "best practice" in the first place, and has no chance of breaking anything, especially in the given situation where the return value is used for array_filter() which absolutely needs an array as input.

chris matthews’s picture

Version: 9.5.x-dev » 11.x-dev
Category: Bug report » Feature request
Priority: Major » Normal
Status: Closed (cannot reproduce) » Active
Issue tags: -Needs steps to reproduce
cedewey’s picture

I'm getting this error which I think is related but I could be wrong,

ValueError: array_rand(): Argument #1 ($array) cannot be empty in array_rand() (line 346 of core/modules/image/src/Plugin/Field/FieldType/ImageItem.php).

when I do the following:

  1. Enable Layout Builder for the Taxonomy term page view mode of a vocabulary.
  2. Add a media field to the Vocabulary.
  3. Navigate to the Manage Layout page for the Taxonomy term page view mode.
heikkiy’s picture

We also encountered the issue after updating modules in our site.

Here is the stacktrace

TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 157 of /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php) 

#0 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php(157): array_filter()
#1 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/modules/views/src/Form/ViewsFormMainForm.php(160): Drupal\media_library\Plugin\views\field\MediaLibrarySelectForm->viewsFormValidate()
#2 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/modules/views/src/Form/ViewsForm.php(182): Drupal\views\Form\ViewsFormMainForm->validateForm()
#3 [internal function]: Drupal\views\Form\ViewsForm->validateForm()
#4 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array()
#5 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Form/FormValidator.php(275): Drupal\Core\Form\FormValidator->executeValidateHandlers()
#6 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm()
#7 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm()
#8 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm()
#9 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm()
#10 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2258): Drupal\Core\Form\FormBuilder->getForm()
#11 [internal function]: Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender()
#12 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array()
#13 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\Core\Render\Renderer->doTrustedCallback()
#14 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\Core\Render\Renderer->doCallback()
#15 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(446): Drupal\Core\Render\Renderer->doRender()
#16 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(446): Drupal\Core\Render\Renderer->doRender()
#17 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
#18 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Template/TwigExtension.php(480): Drupal\Core\Render\Renderer->render()
#19 /var/www/html/shared/public/php/twig/650a7e0ebcf81_media-library-wrapper.htm_aTflB3uzmX2JWrjIHkMDBMHcq/56gbMjyN7mwTRGeljfVgjggUa4hxxXqBMPlWbdw1pVI.php(48): Drupal\Core\Template\TwigExtension->escapeFilter()
#20 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/vendor/twig/twig/src/Template.php(405): __TwigTemplate_c027585ed9a32d430e215bdde6b95984->doDisplay()
#21 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
#22 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
#23 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render()
#24 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
#25 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
#26 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
#27 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(242): Drupal\Core\Render\Renderer->render()
#28 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#29 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(243): Drupal\Core\Render\Renderer->executeInRenderContext()
#30 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
#31 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
#32 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
#33 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
#34 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/vendor/symfony/http-kernel/HttpKernel.php(174): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
#35 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#36 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#37 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#38 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#39 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#40 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#41 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#42 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#43 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle()
#44 /var/www/html/builds/2023-09-19.10-55-49.tag--0.0.47__db59b9ce6/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#45 {main}

Location is an Ajax call to media library: en/media-library?_wrapper_format=drupal_ajax&ajax_form=1&hash=pzpbWl_GZU9CKRNLuuvk-Hd-bX3srQqZfWjcJZjzI9o&media_library_allowed_types%5Bremote_video%5D=remote_video&media_library_opener_id=media_library.opener.field_widget&media_library_opener_parameters%5Bfield_widget_id%5D=field_media_video%3A-field_elements-1-subform-field_elements-0-subform-field_right_column_elements-0-subform&media_library_opener_parameters%5Bentity_type_id%5D=paragraph&media_library_opener_parameters%5Bbundle%5D=video&media_library_opener_parameters%5Bfield_name%5D=field_media_video&media_library_opener_parameters%5Bentity_id%5D=39673&media_library_opener_parameters%5Brevision_id%5D=194833&media_library_remaining=1&media_library_selected_type=remote_video&name=ISS%20support%20process&sort_by=created&views_display_id=widget

poker10’s picture

Status: Active » Needs work
Issue tags: +Needs issue summary update

There is not enough information on what is actually the intention of this issue. Issue summary needs update and the issue title as well.

In #8 it was mentioned, that the patch removed the error, but the behavior was not as intended. So it is possible that using that patch could hide a real problem which has root cause somewhere else.

damienmckenna’s picture

Ran into this on a 10.1.5 site:

URL: /media-library

Query arguments:
_wrapper_format=drupal_ajax
ajax_form=1
ajax_page_state[theme]=gin
ajax_page_state[theme_token]=something
ajax_page_state[libraries]=admin_toolbar/toolbar.tree%2Cadmin_toolbar/toolbar.tree.hoverintent (etc)
media_library_allowed_types[0]=image
media_library_allowed_types[video_remote]=video_remote
media_library_opener_id=media_library.opener.editor
media_library_opener_parameters[filter_format_id]=full_wysiwyg
media_library_remaining=1
media_library_selected_type=image
name=some string
sort_by=created
views_display_id=widget

The referrer on the error report is node/add/story, i.e. a node/add path.

This meant the error happened when someone clicked the Add Media button in the ckeditor 5 toolbar.

I noticed that when the media library is loaded the query arguments are actually like this:

media_library_opener_id=media_library.opener.editor
media_library_allowed_types[0]=image
media_library_allowed_types[video_remote]=video_remote
media_library_selected_type=image
media_library_remaining=1
media_library_opener_parameters[filter_format_id]=full_wysiwyg
hash=something
_wrapper_format=drupal_modal

Does the query arguments from the failed path mean the visitor submitted the filter to narrow the results or that they had just uploaded an image and the media library had reloaded to show the new image selected in the list? But if so, why would the referrer be node/add/story instead of /media-library?

s_leu’s picture

I ran into this too when I had a media bundle that didn't have the media_library view mode configured and enabled. After enabling it on the affected media bundle it works for me. Not 100% that's what was causing it though but maybe worth a try?

s_leu’s picture

I just noticed that this problem doesn't arise any more after i removed the filters for published media in the media library view.

s_leu’s picture

Also as mentioned in #8, the patch from #2 seems not to be a complete solution, as submitting the form with the patch applied gives that error "No items selected".

ion.macaria’s picture

Category: Feature request » Bug report
Issue summary: View changes
Issue tags: -Needs issue summary update

Sorry for confusion, I fished this error from graylog where we are putting ours logs.
After some research I find the way to reproduce it.
So $selected = array_filter($form_state->getValue($this->options['id'], [])); should fix it.

ion.macaria’s picture

Version: 11.x-dev » 9.5.x-dev
StatusFileSize
new848 bytes

Updated patch:

ion.macaria’s picture

Issue summary: View changes
ion.macaria’s picture

Version: 9.5.x-dev » 11.x-dev
ion.macaria’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Hate to do it, but do we know why that value could be empty? Want to make sure we aren't masking a larger issue.

May need a test case also.

ion.macaria’s picture

Status: Needs work » Needs review

@smustgrave value is empty because code tries to get value which is not already found in form after it items list was ajaxfy refreshed.
I don't see the reason to create test for this because by default is clear if you are getting NULL or empty results it means that no item was selected. We just need to provide default value instead NULL to pass array_filter condition.

smustgrave’s picture

So since we know the Id isn't there shouldn't we avoid trying to get the value?

hoaqtcom’s picture

StatusFileSize
new733 bytes

This is another patch for the the same error on the core Views module. Sorry, I don't see another thread for Views so I post it here.

hoaqtcom’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Hiding #29 as that seems to be a separate issue that will need to be investigated.

#22 I tested following the steps in the issue summary but still get an error. That said think we will need test coverage for this.

mohit_aghera’s picture

StatusFileSize
new2.15 KB

I am able to reproduce the issue by following exact steps in the issue summary.
Uploaded the patch for the same.
Not creating MR for now until we have conclusion about the solution.

Hence, keeping issue in needs work and triggering test manually to see how many failures we end up with.

mohit_aghera’s picture

StatusFileSize
new2.15 KB
new962 bytes

There is a typo in patch #32
Resolving that error and few tests are passing on local

larowlan’s picture

+++ b/core/modules/media_library/js/media_library.ui.js
@@ -225,6 +225,21 @@
+        mediaLibraryModalSelection.value = currentSelection.join();

What is the impact of multiple values here, we're joining them with nothing, is that correct?

mohit_aghera’s picture

We are joining with comma here, default argument value in the join() method is comma.
As soon as we keep on selecting multiple media items, all the media item ids are joined with comma and stored in input element field called `current_selection`

`current_selection` hidden input field is retaining all the correct values despite any ajax call.
So in our fix, I am reading the value from the `current_selection` input field and storing values in another hidden input field called `media-library-modal-selection`.

larowlan’s picture

Thanks, I didn't realize comma was the default! Always learn something in the issue queue 🥰

damienmckenna’s picture

Category: Bug report » Feature request
Related issues: +#3404365: Media browser breaks if AJAX disabled on views.view.media_library.yml

It turned out that my site was broken because we'd disabled AJAX on the media_library view, so I opened a separate issue about this: #3404365: Media browser breaks if AJAX disabled on views.view.media_library.yml

saidatom made their first commit to this issue’s fork.

saidatom’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Have not tested but issue summary appears to need some work

Previously tagged for tests which believe are still needed.

damienmckenna’s picture

The merge request's FunctionalJavascript failures all seem to be this error:

PDOException: SQLSTATE[HY000] [1130] Host '127.0.0.1' is not allowed to connect to this MySQL server

alorenc’s picture

Thanks, the latest patch works fine for me.
I can see an error message in case I do not pick any media

alvimurtaza’s picture

Thanks Mohit, I was getting the same error and patch #33 worked fine here and I'm not getting the error anymore.

adamzimmermann’s picture

The MR in its current state fixed the issue I was having. However, I wasn't seeing this in relation to CKEditor. I was having this issue after enabling the core Workspaces module and some associated modules. I can provide more detail if that would be helpful.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

malcomio’s picture

Status: Needs work » Needs review

Seems like there's been some progress since this was last in "Needs review" status

smustgrave’s picture

Status: Needs review » Needs work

This one still appears to need an IS update please.

herved made their first commit to this issue’s fork.

herved’s picture

CI is red because of the change from #3567770: Media Library message persists after deselecting items to fix overflow, which looks like a defect there.
It put the message clearing inside checkEnabled(), and that function runs every time the behaviors run, not only when the selection changes.

The "No items selected." message this MR adds goes into the same container, #media-library-messages.
Nothing is selected at that point, so the selection is within the limit and the clearing empties the container on the next behavior run, right after the message arrives. testEmptyWidgetOverflow fails on that. This MR cannot go green without changing that code.

herved’s picture

This issue is now fixed by #3303889: Media Library: Clicking "Insert selected" with no media selected triggers fatal error latest MR version.
It moves the validation to the hidden selection field, which removes the array_filter() call that throws here.

I ran the steps of this report on that branch: select an item, filter it out of the view, then press Insert selected. The dialog now shows "No items selected." instead of the PHP error, which is what this issue asks for.

So I suggest closing this as a duplicate of #3303889: Media Library: Clicking "Insert selected" with no media selected triggers fatal error.