You are here

function globallink_tmgmt_message_insert in GlobalLink Connect for Drupal 8.2

Same name and namespace in other branches
  1. 8 globallink.module \globallink_tmgmt_message_insert()

Implements hook_ENTITY_TYPE_save().

File

./globallink.module, line 65

Code

function globallink_tmgmt_message_insert(MessageInterface $entity) {
  $langcode = \Drupal::languageManager()
    ->getDefaultLanguage()
    ->getId();

  /** @var \Drupal\tmgmt\JobInterface $job */
  $job = $entity
    ->getJob();

  /** @var \Drupal\tmgmt\TranslatorInterface $translator */

  // Abort if the job has no translator.
  if (!$job
    ->hasTranslator()) {
    return;
  }
  $translator = $job
    ->getTranslator();
  $settings = $translator
    ->getSettings();
  if ($translator
    ->get('plugin') == 'globallink') {
    if (!$entity
      ->get('variables')
      ->isEmpty() && !empty($settings['pd_notify_emails']) && !empty($settings['pd_notify_level'])) {
      if (in_array($entity
        ->getType(), $settings['pd_notify_level'])) {
        $emails = explode(' ', $settings['pd_notify_emails']);

        /** @var \Drupal\Core\Mail\MailManagerInterface $mail_manager */
        $mail_manager = \Drupal::service('plugin.manager.mail');
        $mail_manager
          ->mail('globallink', 'log', $emails, $langcode, [
          'message' => $entity,
        ]);
      }
    }
  }
}