You are here

function _notify_content in Notify 8

Same name and namespace in other branches
  1. 5.2 notify.module \_notify_content()
  2. 5 notify.module \_notify_content()
  3. 6 notify.module \_notify_content()
  4. 7 notify.module \_notify_content()
  5. 1.0.x notify.module \_notify_content()

Formatting of body content.

Parameters

object $node: The node object to format.

object $comment: The comment object to format.

int $view_mode: view mode 0: Title only 1: Title + Teaser/Excerpt 2: Title + Body 3: Title + Body + Fields

Return value

string The transformed string.

1 call to _notify_content()
_notify_send in ./notify.module
Helper function to send the notification e-mail batch.

File

./notify.module, line 492
Notify module sends e-mail digests of new content and comments.

Code

function _notify_content($node, $comment, $view_mode) {
  $txt = '';
  if (0 == $view_mode) {
    return $txt;
  }
  elseif (3 == $view_mode && !$comment) {
    $content = \Drupal::entityTypeManager()
      ->getViewBuilder('node')
      ->view($node, 'full');

    // Run of all children so that every attached field is also included.
    $children = Element::children($content, TRUE);
    foreach ($children as $child) {
      if (isset($content[$child]['#title']) && isset($content[$child][0]['#markup']) && $content[$child]['#access']) {

        //We don't want field name included in the e-mail.

        //$txt .= $content[$child]['#title'] . ': ';
        $txt .= $content[$child][0]['#markup'];
      }
    }
    return MailFormatHelper::htmlToText($txt);
  }
  if (1 == $view_mode) {
    $vmode = 'teaser';
  }
  else {
    $vmode = 'full';
  }
  if ($comment) {

    //@TODO Get trim_length from type.
    if ('teaser' == $vmode) {
      $comment->comment_body['und'][0]['value'] = text_summary($comment->comment_body['und'][0]['value'], NULL, 200);
    }
    $content = \Drupal::entityTypeManager()
      ->getViewBuilder('comment')
      ->view($comment, $node, $vmode);
    if (isset($content['comment_body'][0]['#markup'])) {
      $txt = $content['comment_body'][0]['#markup'];
    }
  }
  else {
    $content = \Drupal::entityTypeManager()
      ->getViewBuilder('node')
      ->view($node, $vmode);
    if (isset($content['body'][0]['#markup'])) {
      $txt = $content['body'][0]['#markup'];
    }
  }
  return MailFormatHelper::htmlToText($txt);
}