function registration_entity_delete in Entity Registration 8
Same name and namespace in other branches
- 8.2 registration.module \registration_entity_delete()
- 7.2 registration.module \registration_entity_delete()
- 7 registration.module \registration_entity_delete()
Implements hook_entity_delete().
File
- ./
registration.module, line 859
Code
function registration_entity_delete($entity, $entity_type) {
// Delete registrations and settings for this host entity .
list($entity_id) = entity_extract_ids($entity_type, $entity);
db_delete('registration')
->condition('entity_id', $entity_id)
->condition('entity_type', $entity_type)
->execute();
db_delete('registration_entity')
->condition('entity_id', $entity_id)
->condition('entity_type', $entity_type)
->execute();
// Remove references to a registration_type on host entities
if ($entity_type == 'registration_type') {
$registration_fields = field_read_fields(array(
'type' => 'registration',
));
if (!empty($registration_fields)) {
foreach (array_keys($registration_fields) as $field_name) {
$query = new EntityFieldQuery();
$result = $query
->fieldCondition($field_name, 'registration_type', $entity->name)
->execute();
foreach ($result as $host_entity_type => $entities) {
$entities = \Drupal::entityManager()
->getStorage($host_entity_type);
foreach ($entities as $entity_id => $host_entity) {
$host_entity->{$field_name}[\Drupal\Core\Language\Language::LANGCODE_NOT_SPECIFIED][0] = NULL;
$host_entity
->save();
}
}
}
}
}
}