Media library does not open when clicking "Add media": “TypeError: Argument 2 passed to Drupal\media_library\MediaLibraryState::create() must be of the type array, null given”

Created on 4 May 2019, over 5 years ago
Updated 10 April 2023, over 1 year ago

Problem/Motivation

After upgrading from Drupal 8.6.15 to 8.7.0, I'm unable to open the media library. I've applied all updates and cleared the caches thoroughly.

Steps to reproduce:

* create a new content type (mine is named "test")
* create a new entityreference field to "Media" entities (enabled the "image" bundle)
* create a new node
* click "Add media"

Expected behaviour: media library pops up like in 8.6.15
Actual behaviour: nothing happens, the POST to /node/add/test?ajax_form=1 returns a 500

And the following error is logged during the POST AJAX request:

TypeError: Argument 2 passed to Drupal\media_library\MediaLibraryState::create() must be of the type array, null given, called in /var/www/drupalvm/drupal/web/core/modules/media_library/src/MediaLibraryState.php on line 98 in Drupal\media_library\MediaLibraryState::create() (line 67 of /var/www/drupalvm/drupal/web/core/modules/media_library/src/MediaLibraryState.php)
#0 /var/www/drupalvm/drupal/web/core/modules/media_library/src/MediaLibraryState.php(98): Drupal\media_library\MediaLibraryState::create(NULL, NULL, NULL, NULL)
#1 /var/www/drupalvm/drupal/web/core/modules/media_library/media_library.module(73): Drupal\media_library\MediaLibraryState::fromRequest(Object(Symfony\Component\HttpFoundation\Request))
#2 [internal function]: media_library_views_post_render(Object(Drupal\views\ViewExecutable), Array, Object(Drupal\views\Plugin\views\cache\Tag))
#3 /var/www/drupalvm/drupal/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('media_library_v...', Array)
#4 /var/www/drupalvm/drupal/web/core/modules/views/src/ViewExecutable.php(1540): Drupal\Core\Extension\ModuleHandler->invokeAll('views_post_rend...', Array)
#5 /var/www/drupalvm/drupal/web/core/modules/views/src/Plugin/views/display/Page.php(183): Drupal\views\ViewExecutable->render()
🐛 Bug report
Status

Needs work

Version

9.5

Component
Media 

Last updated 4 days ago

Created by

🇳🇱Netherlands jsst

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium dieterholvoet Brussels

    The merge request in 🐛 Preview Link does not work with multilingual site Needs work was causing this issue. I discovered the root cause was a call to \Drupal::service('router.route_provider')->getRouteCollectionForRequest($request): that method modifies the passed request object, which happened to be the currently active request. We don't want that to happen in a simple access check, passing a clone to that method fixed the issue.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Ranjit1032002

    Created a patch for the issue mentioned, please review.
    Thank You.

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

    @Ranjit1032002 thank you for the interest but you've been working on a number of these tickets now. Adding just an isset or empty check usually isn't the correct path. As it could be hiding a deeper issue.

    If steps are not provided to reproduce that will be needed.

    As a bug it will need a test case.

    Please do some checks before putting into review.

    Thanks

Production build 0.71.5 2024