Editing content using the Gutenberg editor, adding an image using the Media Library doesn't work.

To reproduce:

  1. Enable Media and Media Library modules
  2. Install Gutenberg editor version 8x-1.11
  3. In the Article or Basic page content type enable the Gutenberg editor
  4. Add content
  5. In the Gutenberg editor, add an image or media block
  6. Click on Media Library
  7. A modal window with a title of Media Library appears with white space and Insert/Cancel buttons at the bottom but no library of image.

I tested this on a brand new site installed using Drupal 9.0.0.

I also tested on a brand new site installed using Drupal 8.9.0 which did not have the issue, but after upgrading the 8.9.0 site to 9.0.0 the issue appears.

I noted this message in the logs:

ArgumentCountError: Too few arguments to function Drupal\media_library\MediaLibraryUiBuilder::__construct(), 4 passed in /var/www/*****/html/core/lib/Drupal/Component/DependencyInjection/Container.php on line 257 and exactly 5 expected in Drupal\media_library\MediaLibraryUiBuilder->__construct() (line 76 of /var/www/*****/html/core/modules/media_library/src/MediaLibraryUiBuilder.php)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

feridun created an issue. See original summary.

szeidler’s picture

In #3038254: Delegate media library access to the "thing" that opened the library the Drupal core service has gotten a 5th parameter "@media_library.opener_resolver".

The constructor of MediaLibraryUiBuilder in Drupal 8 states.

if (!$opener_resolver) {
      @trigger_error('The media_library.opener_resolver service must be passed to ' . __METHOD__ . ' and will be required before Drupal 9.0.0.', E_USER_DEPRECATED);
      $opener_resolver = \Drupal::service('media_library.opener_resolver');
    }

So I see two ways to go.

1. Either dropping < Drupal 8.7 support on Gutenberg and adding the argument to gutenberg.services.yml definition.
2. Or we need to basically mimic the constructor of MediaLibraryUiBuilder in Drupal 8 to the Gutenberg module GutenbergMediaLibraryUiBuilder.

szeidler’s picture

Status: Active » Needs review
FileSize
1.27 KB

Here's a patch for approach 1.

szeidler’s picture

FileSize
1.27 KB

This is actually more correct, as the parameter was added in Drupal 8.7.4

feridun’s picture

A bit more information, on a site that is running 8.9.0 and the Media Library works as expected, there is a difference in the Gutenberg Blocks text format at admin/config/content/formats as per the screenshot below. The one on the left is from the 8.9.0 system and the one on the right is from 9.0.0.

szeidler’s picture

Status: Needs review » Needs work

Actually #3 + #4 makes media_library an implicit dependency, because otherwise the service will not be available. So it might not be the best solution.
So either going with approach 2 described in #2 or we need to make media_library a dependency.

Johan den Hollander’s picture

Tested #4. The mediabrowser is functioning with D9.

Johan den Hollander’s picture

Still needed this patch in 2.0-beta-2
It works well with the patch. It does't work at all without the patch.

Johan den Hollander’s picture

Status: Needs work » Reviewed & tested by the community
szeidler’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for pushing this forward. Unfortunately we still need to resolve my comment in #6 where I like to hear the maintainers step into the discussion.

Patch #4 currently only works when the media library module is enabled. Means it's an implicit dependency, which either would need to be added explicitly or worked around.

natted’s picture

Thanks for pushing this forward. Unfortunately we still need to resolve my comment in #6 where I like to hear the maintainers step into the discussion.
Patch #4 currently only works when the media library module is enabled. Means it's an implicit dependency, which either would need to be added explicitly or worked around.

Patch #4 worked for me. I'm not a maintainer but I will chime in.

Is there a reason why media library wouldn't be a required dependency?

The first thing I did when testing the Gutenberg module is try to add Images/Cover blocks etc. This is the type of functionality that Wordpress has out of the box. Perhaps the idea is for a stripped down Gutenberg (letting site builders control content editing) - I am not sure if this is what the maintainers intend? However, from my perspective: the most obvious use case for Gutenberg within Drupal is to have an editor like that of Wordpress - wouldn't media library be essential then?

Johan den Hollander’s picture

Is there a reason why media library wouldn't be a required dependency?

As seen in this commit Media module should be a requirement.

szeidler’s picture

Status: Needs work » Needs review
FileSize
1.39 KB
263 bytes

As seen in this commit Media module should be a requirement.

Thank you for the observation. Then it's probably alright to make both media and media_library a dependency.

Johan den Hollander’s picture

Just did a quick test agains 2.0.0-beta2, the patch does not apply.
Will check later if 2.x needs a different patch.

  - Installing drupal/gutenberg (2.0.0-beta2): Downloading (100%)         
  - Applying patches for drupal/gutenberg
    https://www.drupal.org/files/issues/2020-10-09/gutenberg-d9_media_library_support-3150127-13_1.patch (#3150127)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-10-09/gutenberg-d9_media_library_support-3150127-13_1.patch
Johan den Hollander’s picture

The patch does work on 2.x-dev.
Should be ok to commit then.

Johan den Hollander’s picture

Status: Needs review » Reviewed & tested by the community
kjankowski’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
991 bytes

Thanks for your work and the insightful discussion.
We don't want to drop support for non-media-library applications, so it's better to avoid making media and media_library dependencies.
The commit mentioned in #12 doesn't make media a dependency as Media API is in core anyway.

Here's a patch that adds media_library.opener_resolver as an optional argument to service gutenberg.media_library.ui_builder. You can check Symfony docs on that here.

szeidler’s picture

That's a good solution and works like charm.

flyke’s picture

Just to inform that patch #17 fixes the issue and also works on Gutenberg 1.11

Claudio Fabio Mazzarago’s picture

Hi,
it doesn't work for me.
I try to apply all of patch in this page.

Drupal 9.1.0
Gutenberg 8.x-2.0-beta2

any suggestions?
thanks so much.

Edit: Now the patch work. I needed to clear the cache.
My apoligize for that and thanks for patch!!!

szeidler’s picture

Did the patch not apply for you or do you still see a blank window? Do you get any error logged? Have you cleared the cache after applying the patch?

Johan den Hollander’s picture

The patch should be applied to the DEV version.

mountcrow’s picture

the patch works for me with:
Drupal 9.1.0
Gutenberg 1.11

janoka’s picture

I tested the latest patch with:

  • Drupal 9.1
  • Gutenberg Editor 8.x-2.0-beta2

I didn't get a blank page anymore.
It works for me perfecly. Thanks!

pelatho’s picture

Uhm... I seem to have this problem even on Drupal 9.1.2, Gutenberg Editor 2.0.0-beta2 :\

Edit: OH, this patch is not in Gutenberg 2.0.0-beta2?

T-Ortan’s picture

I tested the latest patch with:
Drupal core 9.1.2
Gutenberg Editor 8.x-2.0-beta2

This patch didn't work for 8.x-2.0-beta2 (as stated), after downgrading to Gutenberg 8.x-1.11 the latest patch fixed the problem!

Thanks

roborn’s picture

Version: 8.x-1.11 » 8.x-2.x-dev
Assigned: Unassigned » kjankowski
Status: Needs review » Needs work
Issue tags: +ContributionWeekend2021
henrikakselsen’s picture

Tested on a fresh install on Drupal 8.9.13 with 8.x-2.0-beta2 and it seems to work for me without any need for patch

  • kjankowski committed ded5d2d on 8.x-2.x
    Issue #3150127 by szeidler, kjankowski, feridun: Insert Image or Media...
szeidler’s picture

The issue happens on Drupal 9

  • kjankowski committed 7bd2d7d on 8.x-1.x
    Issue #3150127 by szeidler, kjankowski, feridun: Insert Image or Media...
kjankowski’s picture

Exactly, it happens because of changes in Media Library in Drupal 9.
Committed patch on 8.x-1.x and 8.x-2.x.

kjankowski’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.