EventSubscribers lead to fatal errors in automated deployments

Created on 14 June 2022, about 2 years ago
Updated 21 September 2023, 9 months ago

Problem/Motivation

Receiving a fatal error when installing this module via an automated deployment. (Using Ansible in my case).
Problem is the same outlined in #3200062 β†’ , where there is a problem with the autoloader when a custom module, that is already installed, is using constants from EntityHookEvents for subscribed events. After "composer install" that class is expected, but isn't yet available to the "container" because the drupal/hook_event_dispatcher" module has not yet been installed. (often via drush cim)

This results in an error:

Error: Class \Drupal\core_event_dispatcher\EntityHookEvents not found

Note:

My (not ideal) workaround is to hard-code the events, for example:

public static function getSubscribedEvents(): array
  {
    // Hardcoded events due to autoloading issue, @see: https://www.drupal.org/project/drupal/issues/2825358
    return [
      'hook_event_dispatcher.entity.insert' => 'entityInsert',
      'hook_event_dispatcher.entity.delete' => 'entityDelete',
      'hook_event_dispatcher.entity.presave' => 'entityPreSave',
      'hook_event_dispatcher.entity.update' => 'entityUpdate',
    ];
  }

Proposed resolution

πŸ’¬ Support request
Status

Active

Version

3.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ericpugh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom danharper

    I've tried the above but when I edit a node and save it nothing happens.

    Tried using XDEBUG in the entityUpdate function but it never gets there.

Production build 0.69.0 2024