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
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:
- 3338385-php-errors-caused
changes, plain diff MR !5
Comments
Comment #2
mglamanComment #3
mglamanIt looks to be due to
\Drupal\media_library\MediaLibraryUiBuilder::buildMediaTypeMenuIf there is is one media type there is no menu.
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.
Comment #5
mglamanMR 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.
Comment #6
mglamanUnfortunately DrupalCI is failing due to a dev dependency requiring composer-patches, relying on internal CI to verify tests.
Comment #7
davidhernandez@mglaman I am on php 8.1.
Comment #8
mglamanThanks, @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.)
Comment #9
mglamanOkay, this passed on the internal CI, now. Sourcing some reviews.
Comment #11
mglamanMerged and fixed in 1.0.x