You are here

function notifications_widget_entity_delete in Notifications widget 8

Implements hook_entity_delete().

File

./notifications_widget.module, line 143
Contains notifications_widget.module.

Code

function notifications_widget_entity_delete(EntityInterface $entity) {

  // Validate bundle name.
  if (!empty($entity
    ->bundle())) {
    $notificationService = \Drupal::service('notifications_widget.logger');
    $notificationConfig = \Drupal::config('notifications_widget.settings');
    $allowedActions = $entity
      ->bundle() . '_enable';
    $parseAllowedActions = explode(',', $notificationConfig
      ->get($allowedActions));
    $messageConfigField = $entity
      ->bundle() . '_noti_delete_message';
    $routeConfigField = $entity
      ->bundle() . '_redirect_delete_link';
    $configMessage = $notificationConfig
      ->get($messageConfigField);
    $routeLink = $notificationConfig
      ->get($routeConfigField);

    // Prepare message link data.
    $message = [];
    $message['id'] = $entity
      ->id();
    $message['bundle'] = $entity
      ->bundle();
    $message['content'] = $configMessage;
    $message['content_link'] = $routeLink;
    if (in_array('Delete', $parseAllowedActions)) {
      $notificationService
        ->logNotification($message, 'delete', $entity);
    }
  }
}