You are here

function admin_content_notification_send_email in Admin Content Notification 8

Same name and namespace in other branches
  1. 8.2 admin_content_notification.module \admin_content_notification_send_email()
  2. 7.2 admin_content_notification.module \admin_content_notification_send_email()

Send out the admin_content_notification.

Parameters

\Drupal\Core\Entity\EntityInterface $node:

2 calls to admin_content_notification_send_email()
admin_content_notification_node_insert in ./admin_content_notification.module
Implements hook_node_insert().
admin_content_notification_node_update in ./admin_content_notification.module
Implements hook_node_update().

File

./admin_content_notification.module, line 60
Module File, consist all related hooks.

Code

function admin_content_notification_send_email(EntityInterface $node, $is_new = FALSE) {
  global $base_url;
  $node_type = $node
    ->getType();

  // Checking if the nodetype is the one selected.
  $selected_node_types = \Drupal::config('admin_content_notification.settings')
    ->get('admin_content_notification_node_types');
  if (count($selected_node_types) && in_array($node_type, $selected_node_types)) {
    $user_id = $node
      ->getOwner();
    $user_name = $user_id
      ->getUsername();
    $url = Url::fromUri($base_url . '/node/' . $node
      ->id());
    $internal_link = \Drupal::l(t('%title', array(
      '%title' => $node
        ->label(),
    )), $url);
    $variables = array(
      '%user_who_posted' => $user_name,
      '%content_link' => $internal_link,
      '%content_title' => $node
        ->label(),
      '%content_type' => $node_type,
      '%action' => $is_new ? t('posted') : t('updated'),
    );
    $config = Drupal::config('admin_content_notification.settings');
    $subject = t($config
      ->get('admin_content_notification_email_subject'), $variables);
    $body = t($config
      ->get('admin_content_notification_email_body'), $variables);
    $admin_email = $config
      ->get('admin_content_notification_email');
    $params = array(
      'body' => $body,
      'subject' => $subject,
    );
    $key = 'admin_content_notification_key';
    \Drupal::service('plugin.manager.mail')
      ->mail('admin_content_notification', $key, $admin_email, 'en', $params, TRUE);
  }
}