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
- Enable the Organic Groups (og) and OG Menu (og_menu) modules.
- Create a group entity (e.g., a node of a group bundle).
- Run a migration that creates this group entity.
- 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
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 #2
joelpittetThanks 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,
ogwhen 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...Comment #3
joelpittetOh 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
Comment #5
joelpittetComment #6
joelpittetMoving to 2.x
Comment #8
joelpittetThanks @franceslui for putting this together. I have merged it into the 2.x dev branch for alpha5