On a clean 9.5 install with the 1.0.x-dev module. Every time I use the media library, either directly on a field, or with the WYSIWYG button, I get these PHP errors.

Warning: foreach() argument must be of type array|object, null given in Drupal\acquia_dam\AssetLibraryBuilder->addSourceMenu() (line 509 of /var/www/web/modules/contrib/acquia_dam/src/AssetLibraryBuilder.php)
#0 /var/www/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'foreach() argum...', '/var/www/web/mo...', 509)
#1 /var/www/web/modules/contrib/acquia_dam/src/AssetLibraryBuilder.php(509): _drupal_error_handler(2, 'foreach() argum...', '/var/www/web/mo...', 509)
#2 /var/www/web/modules/contrib/acquia_dam/src/AssetLibraryBuilder.php(422): Drupal\acquia_dam\AssetLibraryBuilder->addSourceMenu(Object(Drupal\media_library\MediaLibraryState), 'core')
#3 [internal function]: Drupal\acquia_dam\AssetLibraryBuilder->buildUi(Object(Drupal\media_library\MediaLibraryState))
#4 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
...
Warning: Undefined array key "#links" in Drupal\acquia_dam\AssetLibraryBuilder->addSourceMenu() (line 509 of /var/www/web/modules/contrib/acquia_dam/src/AssetLibraryBuilder.php)
#0 /var/www/web/core/includes/bootstrap.inc(347): _drupal_error_handler_real(2, 'Undefined array...', '/var/www/web/mo...', 509)
#1 /var/www/web/modules/contrib/acquia_dam/src/AssetLibraryBuilder.php(509): _drupal_error_handler(2, 'Undefined array...', '/var/www/web/mo...', 509)
#2 /var/www/web/modules/contrib/acquia_dam/src/AssetLibraryBuilder.php(422): Drupal\acquia_dam\AssetLibraryBuilder->addSourceMenu(Object(Drupal\media_library\MediaLibraryState), 'core')
#3 [internal function]: Drupal\acquia_dam\AssetLibraryBuilder->buildUi(Object(Drupal\media_library\MediaLibraryState))
#4 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
...

Issue fork acquia_dam-3338385

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

davidhernandez created an issue. See original summary.

mglaman’s picture

Assigned: Unassigned » mglaman
mglaman’s picture

It looks to be due to \Drupal\media_library\MediaLibraryUiBuilder::buildMediaTypeMenu

If there is is one media type there is no menu.

    // Add the menu for each type if we have more than 1 media type enabled for
    // the field.
    $allowed_type_ids = $state->getAllowedTypeIds();
    if (count($allowed_type_ids) <= 1) {
      return [];
    }

Otherwise $build['menu']['link']['#links'] would be an array. This method does not seem to be supporting this. I actually think it may have been a silent failure on PHP 7.4 and started throwing notices on PHP 8.0

@davidhernandez can provide the PHP version and number of media types configured for the field or WYSIWYG? I want to try and reproduce versus just my hunches.

mglaman’s picture

Status: Active » Needs review

MR with the fix. I want to get test coverage for this. We manually tested media library instances configured with one instance and didn't get these warnings, and tests should have caught them as well.

mglaman’s picture

Unfortunately DrupalCI is failing due to a dev dependency requiring composer-patches, relying on internal CI to verify tests.

davidhernandez’s picture

@mglaman I am on php 8.1.

mglaman’s picture

Thanks, @davidhernandez! I am too. I think the problem is that any test which asserted the media library installed the module's own config. This new test does not and asserts the media type links. That's why it didn't occur. I guess the runtime QA environment didn't for unknown reasons (I'll check that later.)

mglaman’s picture

Assigned: mglaman » Unassigned

Okay, this passed on the internal CI, now. Sourcing some reviews.

  • mglaman authored 69ffb039 on 1.0.x
    Issue #3338385 by mglaman: PHP errors caused by media library popup (#...
mglaman’s picture

Status: Needs review » Fixed

Merged and fixed in 1.0.x

Status: Fixed » Closed (fixed)

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