You are here

function opigno_module_entity_delete in Opigno module 3.x

Same name and namespace in other branches
  1. 8 opigno_module.module \opigno_module_entity_delete()

Implements hook_entity_delete().

File

./opigno_module.module, line 1253
Contains opigno_module.module.

Code

function opigno_module_entity_delete(EntityInterface $entity) {
  if ($entity
    ->getEntityTypeId() === 'opigno_group_content' && $entity
    ->getGroupContentTypeId() === 'ContentTypeModule' && $entity
    ->getGroup() && $entity
    ->getEntityId()) {
    $lp_module_availability = LPModuleAvailability::loadByProperties([
      'group_id' => $entity
        ->getGroup()
        ->id(),
      'entity_id' => $entity
        ->getEntityId(),
    ]);
    if ($lp_module_availability) {
      $lp_module_availability = current($lp_module_availability);
      try {
        $lp_module_availability
          ->delete();
      } catch (\Exception $e) {
        \Drupal::logger('opigno_module')
          ->error($e
          ->getMessage());
        \Drupal::messenger()
          ->addMessage($e
          ->getMessage(), 'error');
      }
    }
  }
}