Missing og_audience field reference causes fatal errors in og_menu_entity_delete() during entity deletion

Created on 6 June 2025, about 1 month ago

Problem/Motivation

When deleting a group entity or rolling back a migration that removes group entities, fatal errors are triggered due to an invalid field reference in the og_menu_entity_delete() function.

Steps to reproduce

  1. Enable the Organic Groups (og) and OG Menu (og_menu) modules.
  2. Create a group entity (e.g., a node of a group bundle).
  3. Run a migration that creates this group entity.
  4. Roll back the migration (e.g., using drush migrate:rollback).

The expected result is that the group entity is deleted successfully. However, the following errors are thrown:

In SqlContentEntityStorage.php line 763:
  'og_audience' not found
In Tables.php line 369:
  'og_audience' not found

These errors originate from the following lines in the og_menu_entity_delete() function, defined in the og_menu.module file:

      $storage = \Drupal::entityTypeManager()->getStorage('ogmenu_instance');
      $properties = [OgGroupAudienceHelper::DEFAULT_FIELD => $entity->id()];
      /** @var \Drupal\og_menu\Entity\OgMenuInstance $instance */
      foreach ($storage->loadByProperties($properties) as $instance) {
        $instance->delete();
      }

The ogmenu_instance entity type does not define the og_audience field (OgGroupAudienceHelper::DEFAULT_FIELD), causing loadByProperties() to throw an exception, resulting in fatal errors.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada franceslui

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024