You are here

function notifications_widget_entity_update in Notifications widget 8

Implements hook_entity_update().

File

./notifications_widget.module, line 114
Contains notifications_widget.module.

Code

function notifications_widget_entity_update(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_update_message';
    $routeConfigField = $entity
      ->bundle() . '_redirect_update_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('Update', $parseAllowedActions)) {
      $notificationService
        ->logNotification($message, 'update', $entity);
    }
  }
}