protected function OgDeleteOrphansBase::deleteOrphan in Organic groups 8
Deletes an orphaned group content entity if it is fully orphaned.
Parameters
string $entity_type: The group content entity type.
string $entity_id: The group content entity ID.
3 calls to OgDeleteOrphansBase::deleteOrphan()
- Batch::process in src/
Plugin/ OgDeleteOrphans/ Batch.php - Starts the deletion process.
- Cron::processItem in src/
Plugin/ OgDeleteOrphans/ Cron.php - Works on a single queue item.
- Simple::process in src/
Plugin/ OgDeleteOrphans/ Simple.php - Starts the deletion process.
File
- src/
OgDeleteOrphansBase.php, line 142
Class
- OgDeleteOrphansBase
- Base implementation for OgDeleteOrphans plugins.
Namespace
Drupal\ogCode
protected function deleteOrphan($entity_type, $entity_id) {
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id);
// The entity might already be removed by other modules that implement
// hook_entity_delete().
if (!$entity) {
return;
}
// Only delete group content that is fully orphaned, i.e. it is no longer
// associated with any groups.
if ($this->groupAudienceHelper
->hasGroupAudienceField($entity
->getEntityTypeId(), $entity
->bundle())) {
// Only do a group count if the entity is actually group content.
$group_count = $this->membershipManager
->getGroupCount($entity);
if ($group_count == 0) {
$entity
->delete();
}
}
else {
$entity
->delete();
}
}