Problem/Motivation
Installing Able Player on a fresh Drupal 11.3.5 (where media and media_library are not yet enabled) causes a crash during installation.
The root cause is that ableplayer_install() in ableplayer.install manipulates Media entity types, bundles, field storages, and form/view displays. However, hook_install() fires during the module's own installation, at which point the dependencies (media, media_library) are being installed in the same batch and their configuration is not yet fully available.
Error:
InvalidArgumentException: Missing required properties for an EntityDisplay entity.
in Drupal\Core\Entity\EntityDisplayBase->__construct() (line 134 of core/lib/Drupal/Core/Entity/EntityDisplayBase.php).
#0 core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php(188)
#1 core/lib/Drupal/Core/Entity/EntityStorageBase.php(453)
#2 core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(168)
#3 core/lib/Drupal/Core/Entity/EntityStorageBase.php(340)
#4 core/modules/field/src/EntityDisplayRebuilder.php(85)
#5 core/modules/field/src/Hook/FieldHooks.php(343)
...
#15 core/lib/Drupal/Core/Config/ConfigInstaller.php(429)
#16 core/lib/Drupal/Core/Config/ConfigInstaller.php(299)
#17 core/lib/Drupal/Core/Config/ConfigInstaller.php(208): installDefaultConfig('module', 'media', ...)
#18 core/lib/Drupal/Core/Extension/ModuleInstaller.php(468)
#19 core/lib/Drupal/Core/Extension/ModuleInstaller.php(229)
The crash occurs within ConfigInstaller::installDefaultConfig() for the media module — its config is still being imported when ableplayer's hook_install() fires.
Steps to reproduce
- Start with a fresh Drupal 11.3.5 installation (standard profile, without Media/Media Library enabled)
- Install the Able Player module via the UI or drush en ableplayer
- Installation crashes with the above error
Workaround: Manually enable media and media_library first, then install ableplayer.
Proposed resolution
Move the field/display setup logic from hook_install() (in ableplayer.install) to hook_modules_installed() (in ableplayer.module), with a guard:
function ableplayer_modules_installed($modules) {
if (!in_array('ableplayer', $modules)) {
return;
}
// ... existing setup code from hook_install() ...
}
hook_modules_installed() is invoked after all modules in the batch are fully installed and their configuration is available, which ensures that Media entity types, bundles, and displays exist before Able Player tries to manipulate them.
Issue fork ableplayer-3581910
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 #3
dpiet commentedComment #4
themusician commentedThanks for finding this. In trying this code, I get this error while installing. I have not used the https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension... before, but it seems like it should do what you suggest.
Can you reproduce a clean install with this branch?
Comment #5
dpiet commentedHi @themusician, I've tested the branch 3581910-installation-crash-on on a fresh Drupal 11.3.5 installation and cannot reproduce the error. Here are the scenarios I tested, all successful:
Could you confirm:
- Your Drupal core version?
- Your installation profile?
- Whether any other modules were enabled at the same time?
Comment #7
themusician commentedHi,
Thank you for outlining this further. I was able to get it to work this time. I had been running 11.3.5 with the standard profile. I am not sure what was going on, it seemed like the changes you outlined never took effect locally. I have committed this and am pushing a new stable tag release.
Cheers!
Comment #9
dpiet commentedThanks for the merge and the credit @themusician!
Comment #10
themusician commentedThanks for a great report and for writing the fix. It is appreciated.