Opener id is null when clicking "Add Media" button using the media library popup

Created on 14 August 2019, almost 5 years ago
Updated 11 April 2024, 2 months ago

After upgrading one our sites from 8.6.16 to 8.7.6 the media library functionality stopped working.

What are the steps required to reproduce the bug?

  • Install Drupal 8.6.16
  • Upgrade to Drupal 8.7.6
  • Add a new media field to a content type
  • Setup a new media entity reference field and set the form widget to "Media Library "
  • Create a new piece of content and click the add media button

What behaviour were you expecting?

The media library popup opened and allows you to pick an image.

What happened instead?

A Drupal AJAX error triggered and upon checking the logs I can see the following error:

InvalidArgumentException: The opener ID parameter is required and must be a string. in Drupal\media_library\MediaLibraryState->validateRequiredParameters() (line 146 of web/core/modules/media_library/src/MediaLibraryState.php).

I did a quick bit of debugging for this and it seems that the opener id parameter was null and didn't seem to be passed through to the request object.

I'm not certain if it is related but found this issue that seems like it implements the opener id functionality.

https://www.drupal.org/project/drupal/issues/3038254

Extra Information

PHP Version: 7.1.8

🐛 Bug report
Status

Active

Version

1.0

Component

Integration with other module

Created by

Live updates comments and jobs are added and updated live.
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.

  • 🇮🇳India akhilsoni Ahmedabad

    I am also facing same issue, I tried the Metatag hack which is mentioned #9 and it dosen't worked for me. I have also applied #15 patch and also that is not working for me. Still looking for solution.

  • 🇺🇸United States wells Seattle, WA

    I never saw this in 8.x-1.x versions but I am now seeing the exact same issues as described in the initial issue report after upgrading to 2.0.0. Looks like there isn't much here to go on but I'll try to dig in and follow up on what I find. Downgrading to 8.x-1.26 works around the issue (at least in my use case).

    I'm leaving the version as 8.x-1.x-dev here since the issue still seems to be active there as well.

  • 🇺🇸United States wells Seattle, WA

    On the 2.0.x-dev version this is at least somewhat related to 📌 Support JSON API, REST, GraphQL and custom normalizations via new computed field Fixed .

    In my testing I found the issue is triggered somewhere along the line when the metatag_computed field is computed in \Drupal\metatag\Plugin\Field\MetatagEntityFieldItemList::computeValue. Specifically it seems to come up after all the relevant entities for the media library view have been computed (i.e. there doesn't appear to be a specific entity or anything triggering the issue).

    I further traced this to \Drupal\metatag\MetatagManager::processTagValue where if I comment out the line handling token replacement the issue goes away. This obviously is not a solution as it disables token replacement in tags but maybe it points to something deeper in \Drupal\Core\Utility\Token::doReplace? There were kind of recent changes to that handling in #2580723: Fix token system confusion, with new function Token::replacePlain() but I haven't made it so far as testing this with different versions of Drupal core (and I'm thinking that's a dead end anyway).

    I also haven't been able to test this with a fresh Drupal installation and the relevant modules yet so I'm not ruling out something specific to our entity configurations or hooks.

  • 🇺🇸United States wells Seattle, WA

    Following up on the token lead... in my metatag.metatag_defaults.global.yml config I have (among other things):

    uuid: 0031d9a6-85cc-41f3-aa0b-46660705ab08
    langcode: en
    status: true
    dependencies: {  }
    _core:
      default_config_hash: sL588ui1E_8-2c_UupwyYxcqX2OVyMFp3HTLbbFqvPc
    id: global
    label: Global
    tags:
      title: '[current-page:title] | [site:name]'
      canonical_url: '[current-page:url]'
      og_url: '[current-page:url]'
      og_site_name: '[site:name]'
      og_title: '[current-page:title]'
    

    I found that if I remove the two references to [current-page:url] from the config the issue goes away. So it seems this somehow has to do with the handling of that particular token for Media entities (or at least for Media entities as configured on my site).

    And thinking about it now having current-page references in the global config is probably unwise. So at least in this case I will probably work around the issue but making those configuration more precise.

  • 🇺🇸United States davedg629

    I'm getting this same issue (media library pop-up not working) after upgrade from 8.x-1.26 to 2.0.0. I'm getting a similar error to the one posted in the original summary of this issue:

    StatusText: error
    ResponseText: The website encountered an unexpected error. Please try again later.InvalidArgumentException: The opener ID parameter is required and must be a string. in Drupal\media_library\MediaLibraryState->validateRequiredParameters() (line 143 of core/modules/media_library/src/MediaLibraryState.php).

    I'm testing with Drupal 9.5.11 and PHP 8.1.

    I've downgraded to 8.x-1.26 for now to resolve the issue.

  • 🇬🇷Greece s.messaris

    This is still an issue, steps from #9 worked for me.

  • 🇺🇸United States davedg629

    Fix in #9 also worked for me. Additionally, I updated the Open Graph -> Page URL setting to "[media:url]" as well, as recommended in #21.

Production build 0.69.0 2024