전체 노드를 이메일로 전송 (템플릿 내용 포함) 때 이메일이 자동으로

내 자신의 사용자 정의 node.tpl.php 파일을 만들었습니다. 이제 사용자가 해당 컨텐츠 유형의 새 노드를 작성할 때마다 전체 노드를 이메일로 보내려고합니다 (노드 .tpl.php 파일의 모든 HTML이 이메일 친화적임을 확인했습니다).

어떻게해야합니까? 이상적으로는 노드가 저장 될 때 이메일이 자동으로 특정 이메일 주소로 가고 싶습니다.

나는 규칙HTML 메일 의 조합이 내가 원하는 것을 달성 할 수 있음을 발견했다 . 예외 … 규칙 작업을 생성 할 때 전체 노드 (node.tpl.php 테마 포함)를 이메일로 보낼 수있는 옵션이 없습니다. 규칙은 테마없이 특정 노드 필드를 전자 메일로 보내는 옵션 만 제공합니다.

어떤 제안이라도 가장 감사하겠습니다!



답변

다른 접근법이 있습니다. ( 이 샌드 박스 에서 코드를 사용할 수 있습니다 .)

nodemail.info

name = Nodemail
description = Sends node e-mails.
core = 7.x

nodemail.install ‘

<?php
function nodemail_enable() {
  $current = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
  $addition = array('nodemail' => 'NodemailMailSystem');
  variable_set('mail_system', array_merge($current, $addition));
}

function nodemail_disable() {
  $mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
  unset($mail_system['nodemail']);
  variable_set('mail_system', $mail_system);
}

nodemail.module

<?php
class NodemailMailSystem extends DefaultMailSystem {
  public function format(array $message) {
    $message['body'] = implode("\n\n", $message['body']);
    $message['body'] = drupal_wrap_mail($message['body']);
    return $message;
  }
}

function nodemail_mail($key, &$message, $params) {
  switch ($key) {
    case 'node_mail':
      $message['headers']['Content-Type'] = 'text/html; charset=UTF-8;';
      $message['subject'] = $params['subject'];
      $message['body'][] = $params['body'];
      break;
  }
}

function nodemail_node_insert($node) {
  if ($node->type == 'mycontenttype') {
    $params['subject'] = 'Node "' . $node->title . '" was created';
    $params['body'] = render(node_view($node));
    $to = variable_get('site_mail', '');
    $from = 'noreply@example.com';
    $lang = language_default();
    drupal_mail('nodemail', 'node_mail', $to, $lang, $params, $from);
  }
}

설치 파일 내용 및 NodemailMailSystem 클래스는이 모듈이 html 전자 우편을 보낼 수 있도록하는 데 사용됩니다. 다른 두 가지 함수는 의 노드 가 생성 될 때 전자 메일 보내기를 처리하는 hook_mail ()hook_node_insert ()의 구현입니다 mycontenttype. 주목해야 할 것은 Drupal은 노드 뷰에 노드 생성 페이지 (또는 테마가없는 경우 코어 node.tpl.php)에 사용되는 테마의 노드 템플릿 파일을 사용한다는 것입니다. . 여기에 사용 된 node_view ()drupal_mail () 함수 를 점검 할 수도 있습니다. 이 모든 것이 Drupal 7 핵심 기능과 함께 작동해야합니다 (기여 된 모듈이 필요하지 않음).


답변

렌더링 된 노드 인 토큰을 만들거나 렌더링 된 노드를 보낼 사용자 지정 규칙 작업을 만들 수 있습니다.

당신은보고 싶어

$build = node_view($node);
$html = render($build);

코드로 업데이트

이 코드는 규칙에서 액세스 할 수있는 모든 노드에 특성을 추가하는 방법을 보여줍니다. 이 모듈을 만들었습니다.googletorp

/**
 * Implements hook_entity_property_info_alter().
 */
function googletorp_entity_property_info_alter(&$info) {
  // Add the current user's shopping cart to the site information.
  $info['node']['properties']['rendered_node'] = array(
    'label' => t("Rendered_node"),
    'description' => t('The full rendered node.'),
    'getter callback' => 'googletorp_render_node',
  );
}

/**
 * Return a rendered node as HTML.
 */
function googletorp_render_node($node) {
  return render(node_view($node));
}

첫 번째 함수는 노드에 속성을 추가하는 후크입니다. 콜백에서 데이터를 제공하도록 정의됩니다. 두 번째 함수는 렌더링 된 노드를 반환하는 실제 콜백입니다.

이것이 작동하려면 엔티티 API 모듈 의 일부인 엔티티 토큰 모듈을 설치해야 하지만, 어쨌든 규칙에 필요합니다.


답변

다른 옵션은 내 모듈 Entity2Text (DRupal 7)를 사용하는 것입니다.

현재 엔터티의 모든보기 모드에 대해 “텍스트 내보내기”토큰을 제공합니다. 이것은 많은 필드 유형에 효과적이지만 주소 필드와 같은 더 복잡한 유형에 문제가 있습니다.

“htmlexport”도 추가하겠습니다. 이 지점을 체크 아웃하려면 http://drupalcode.org/project/entity2text.git/shortlog/refs/heads/7.x-1-htmlexport

여전히 규칙과 MimeMail (또는 위에서 언급 한 htmlmail) 을 사용해야 합니다.


답변