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.

Issue fork og_menu-3528716

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

franceslui created an issue. See original summary.

joelpittet’s picture

Thanks for creating the issue @franceslui. When we looked at this together this afternoon, it appears this field is only used here, and nowhere else outside of tests. I believe, but could be wrong (will check with @claudiu.cristea), that the intent is for this to be field name agnostic, though a field is indeed expected.

My gut is saying use \Drupal\og\OgGroupAudienceHelper::getAllGroupAudienceFields:
https://git.drupalcode.org/project/og/blob/404bb45bd8849cca32f34e5a78c4f...
and get all the fields.

The only question this solution brings up is that this module should likely install a default as, og when group content is being created, or maybe it does and we deleted it, but from looking at the code it didn't seem to be the case...

joelpittet’s picture

Oh while getting the issue ready to add this loop through fields... I see that the field will get created automatically on the first og menu that gets created...

Still needs fixing, but mitigated by finishing the config

joelpittet’s picture

Status: Active » Needs review
joelpittet’s picture

Version: 8.x-1.x-dev » 2.x-dev

Moving to 2.x

  • joelpittet committed e9eeb907 on 2.x
    fix: #3528716 Missing og_audience field reference causes fatal errors in...
joelpittet’s picture

Status: Needs review » Fixed

Thanks @franceslui for putting this together. I have merged it into the 2.x dev branch for alpha5

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.