function activity_creator_entity_delete in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 8.2 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 8.3 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 8.4 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 8.5 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 8.6 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 8.7 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 8.8 modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 10.3.x modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 10.0.x modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 10.1.x modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
- 10.2.x modules/custom/activity_creator/activity_creator.module \activity_creator_entity_delete()
Implements hook_entity_delete().
Delete activity items when related entities are deleted.
@TODO: When group is deleted delete activities where group is recipient. @TODO: When user is deleted delete activities where user is recipient.
File
- modules/
custom/ activity_creator/ activity_creator.module, line 244 - Activity Creator module file.
Code
function activity_creator_entity_delete(EntityInterface $entity) {
// TODO Move this into a service.
if ($entity !== NULL) {
$entity_type = $entity
->getEntityTypeId();
$entity_id = $entity
->id();
if ($entity_type !== 'activity') {
$entity_query = \Drupal::entityQuery('activity');
$entity_query
->condition('field_activity_entity.target_id', $entity_id, '=');
$entity_query
->condition('field_activity_entity.target_type', $entity_type, '=');
$ids = $entity_query
->execute();
if (!empty($ids)) {
entity_delete_multiple('activity', $ids);
}
}
if ($entity_type == 'user' || $entity_type == 'group') {
$entity_query = \Drupal::entityQuery('activity');
$entity_query
->condition('field_activity_recipient_' . $entity_type, $entity_id, '=');
$ids = $entity_query
->execute();
if (!empty($ids)) {
entity_delete_multiple('activity', $ids);
}
}
if ($entity_type == 'group_content') {
/** @var \Drupal\group\Entity\GroupContent $group_content */
$group_content = $entity;
$linked_entity = $group_content
->getEntity();
$group = $group_content
->getGroup();
if ($linked_entity && $linked_entity
->getEntityTypeId() === 'node' && $group
->id()) {
$entity_query = \Drupal::entityQuery('activity');
$entity_query
->condition('field_activity_entity.target_id', $linked_entity
->id(), '=');
$entity_query
->condition('field_activity_entity.target_type', $linked_entity
->getEntityTypeId(), '=');
$entity_query
->condition('field_activity_recipient_group', $group
->id(), '=');
$ids = $entity_query
->execute();
if (!empty($ids)) {
entity_delete_multiple('activity', $ids);
}
}
}
}
}