Problem/Motivation
I have defined a custom AssetMediaSource plugin. Now I'm getting a fatal error when trying to edit content.
TypeError: Drupal\acquia_dam\EmbedCodeFactory::getSelectOptions(): Return value must be of type array, null returned in Drupal\acquia_dam\EmbedCodeFactory::getSelectOptions() (line 109 of /app/docroot/modules/contrib/acquia_dam/src/EmbedCodeFactory.php).
which is accompanied by a warning:
Warning: Undefined array key "[my AssetMediaSource plugin id]" in Drupal\acquia_dam\EmbedCodeFactory::getSelectOptions() (line 109 of /app/docroot/modules/contrib/acquia_dam/src/EmbedCodeFactory.php)
Steps to reproduce
Define a custom AssetMediaSource and then do something that calls EmbedCodeFactory::getSelectOptions()
Proposed resolution
Long term, there needs to be some way to alter or affect how EmbedCodeFactory::getSelectOptions() works. It has a hardcoded list of AssetMediaSource ids that I don't see any way to alter.
Short term, it might be enough to change the return form:
return $asset_type ? $mapping[$asset_type] : $mapping;
to something like
return $asset_type ? ($mapping[$asset_type] ?? $mapping['General']) : $mapping;
That $mapping['General'] is defined earlier and looks like it's never used. This is probably how it was supposed to be used.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork acquia_dam-3565081
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
Comment #2
danflanagan8Comment #4
danflanagan8I opened an MR with a test that triggers the bug. It calls
EmbedCodeFactory::getSelectOptions('assettestmediasource')and gets this output:Comment #5
danflanagan8I made what's probably the smallest reasonable change that prevents this error.
The more look at this class, though, it really seems like code that should get absorbed into the asset type plugins. The plugins themselves should know what embed options they support, no?
I see there's an open issue to improve performance (#3539187: EmbedCodeFactory::getSelectOptions performance improvements). I wonder if it's being discussed to scrap this class entirely and instead add some methods to
MediaSourceTypeInterfaceand/orAssetMediaSourceManager.