Media Library: Argument #1 ($array) must be of type array, null given in array_filter().

Created on 10 February 2023, almost 2 years ago

PHP error

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

🐛 Bug report
Status

Active

Version

9.5

Component
Media 

Last updated 13 minutes ago

Created by

🇷🇴Romania ion.macaria Bucharest, 🇷🇴

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ion.macaria
  • Status changed to Needs review almost 2 years ago
  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴

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

  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴
  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴
  • Status changed to Postponed: needs info almost 2 years ago
  • We require some steps to reproduce. A bug like this would show in automated tests, so it must be an untested feature.

  • 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.

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

  • 🇫🇷France pacproduct

    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.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    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.

  • 🇻🇳Vietnam mrddthi

    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.

  • Issue was unassigned.
  • Status changed to Closed: cannot reproduce about 1 year ago
  • 🇺🇸United States Chris Matthews

    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.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    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.

  • Status changed to Active about 1 year ago
  • 🇺🇸United States cedewey Denver, CO

    I'm getting this error 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.
  • 🇫🇮Finland heikkiy Oulu

    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

  • Status changed to Needs work about 1 year ago
  • 🇸🇰Slovakia poker10

    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.

  • 🇺🇸United States DamienMcKenna NH, USA

    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?

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

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

  • 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".

  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴

    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.

  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴

    Updated patch:

  • last update about 1 year ago
    30,374 pass
  • last update about 1 year ago
    28,526 pass
  • last update about 1 year ago
    29,672 pass
  • last update about 1 year ago
    30,425 pass
  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴
  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴
  • Status changed to Needs review about 1 year ago
  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    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.

  • Status changed to Needs review about 1 year ago
  • 🇷🇴Romania ion.macaria Bucharest, 🇷🇴

    @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.

  • 🇺🇸United States smustgrave

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

  • 🇻🇳Vietnam hoaqtcom

    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.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    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.

  • 🇮🇳India mohit_aghera Rajkot

    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.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 12 months ago
    30,662 pass, 9 fail
  • 🇮🇳India mohit_aghera Rajkot

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

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7 updated deps
    last update 12 months ago
    30,687 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7 updated deps
    last update 12 months ago
    30,687 pass, 2 fail
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
    +++ 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?

  • 🇮🇳India mohit_aghera Rajkot

    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`.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

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

  • 🇺🇸United States DamienMcKenna NH, USA

    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: 🐛 Media browser breaks if AJAX disabled on views.view.media_library.yml Active

  • First commit to issue fork.
  • Pipeline finished with Success
    5 months ago
    Total: 632s
    #202022
  • Status changed to Needs review 5 months ago
  • 🇵🇹Portugal saidatom Lisbon
  • Status changed to Needs work 5 months ago
  • 🇺🇸United States smustgrave

    Have not tested but issue summary appears to need some work

    Previously tagged for tests which believe are still needed.

  • Pipeline finished with Canceled
    5 months ago
    Total: 154s
    #202107
  • Pipeline finished with Failed
    5 months ago
    Total: 719s
    #202109
  • 🇺🇸United States DamienMcKenna NH, USA

    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

  • Pipeline finished with Failed
    5 months ago
    Total: 3540s
    #205160
  • Pipeline finished with Failed
    5 months ago
    #205580
  • Pipeline finished with Failed
    5 months ago
    Total: 560s
    #205597
  • Pipeline finished with Failed
    5 months ago
    Total: 511s
    #205604
  • Pipeline finished with Failed
    5 months ago
    Total: 511s
    #205632
  • Pipeline finished with Failed
    5 months ago
    Total: 588s
    #205678
  • Pipeline finished with Failed
    5 months ago
    Total: 188s
    #205684
  • Pipeline finished with Success
    5 months ago
    Total: 604s
    #205687
  • Pipeline finished with Failed
    5 months ago
    Total: 168s
    #206579
  • Pipeline finished with Success
    5 months ago
    Total: 603s
    #206582
  • 🇵🇱Poland alorenc Wolsztyn, 🇵🇱

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

  • 🇮🇳India AlviMurtaza

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

  • 🇺🇸United States adamzimmermann

    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.

Production build 0.71.5 2024