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

  1. Start with a fresh Drupal 11.3.5 installation (standard profile, without Media/Media Library enabled)
  2. Install the Able Player module via the UI or drush en ableplayer
  3. 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

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

dpiet created an issue. See original summary.

dpiet’s picture

Status: Active » Needs review
themusician’s picture

Status: Needs review » Needs work

Thanks 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?

The website encountered an unexpected error. Try again later.

InvalidArgumentException: Missing required properties for an EntityDisplay entity. in Drupal\Core\Entity\EntityDisplayBase->__construct() (line 134 of core/lib/Drupal/Core/Entity/EntityDisplayBase.php).

Drupal\Core\Entity\Entity\EntityFormDisplay->__construct() (Line: 453)
Drupal\Core\Entity\EntityStorageBase->mapFromStorageRecords() (Line: 168)
Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple() (Line: 340)
Drupal\Core\Entity\EntityStorageBase->loadMultiple() (Line: 267)
Drupal\Core\Entity\EntityStorageBase->load() (Line: 195)
ableplayer_modules_installed()
call_user_func_array() (Line: 389)
Drupal\Core\Extension\ModuleHandler->{closure:Drupal\Core\Extension\ModuleHandler::invokeAll():388}() (Line: 340)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 257)
Drupal\Core\Extension\ModuleInstaller->install() (Line: 83)
Drupal\Core\ProxyClass\Extension\ModuleInstaller->install() (Line: 503)
Drupal\system\Form\ModulesListForm->submitForm() (Line: 108)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 45)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 615)
Drupal\Core\Form\FormBuilder->processForm() (Line: 347)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}() (Line: 634)
Drupal\Core\Render\Renderer::{closure:Drupal\Core\Render\Renderer::executeInRenderContext():634}()
Fiber->start() (Line: 635)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 118)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 92)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 54)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 745)
Drupal\Core\DrupalKernel->handle() (Line: 19)

dpiet’s picture

Status: Needs work » Needs review

Hi @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:

  1. Standard profile, UI — Install Able Player via admin/modules → OK
  2. Minimal profile, UI — Install Able Player via admin/modules (media + media_library installed as dependencies in the same batch) → OK
  3. Minimal profile, drush — drush pm:install ableplayer -y (all dependencies installed in the same batch) → OK
  4. Minimal profile, drush, media pre-installed — Install media + media_library first, then ableplayer separately → OK
  5. Minimal profile, UI, media pre-installed — Install media + media_library first via UI, then Able Player separately → OK

Could you confirm:
- Your Drupal core version?
- Your installation profile?
- Whether any other modules were enabled at the same time?

  • themusician committed 0a3ed6e4 on 3.x authored by dpiet
    Issue #3581910 by dpiet: Move hook_install() to hook_modules_installed...
themusician’s picture

Status: Needs review » Fixed

Hi,

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!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

dpiet’s picture

Thanks for the merge and the credit @themusician!

themusician’s picture

Thanks for a great report and for writing the fix. It is appreciated.

Status: Fixed » Closed (fixed)

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