You are here

subscriptions_cck.module in Subscriptions 6

Same filename and directory in other branches
  1. 5.2 subscriptions_cck.module

Provide support of CCK fields by adding corresponding mailvars.

File

subscriptions_cck.module
View source
<?php

/**
 * @file
 *
 * Provide support of CCK fields by adding corresponding mailvars.
 */

/**
 * Implementation of hook_subscriptions_tokens_list().
 *
 * Provide replacable tokens for mail_edit.
 *
 * @ingroup hooks
 */
function subscriptions_cck_subscriptions_tokens_list($mailkey, $options = array()) {
  $tr = 't';
  $variables = array(
    '%fieldname' => '<fieldname>',
    '!content_type',
    $tr('content type'),
  );
  $tokens = array(
    '!ccklabel_&lt;fieldname&gt;' => t('The label for the CCK field %fieldname, as defined for your !content_type.', $variables),
    '!cckvalue1_&lt;fieldname&gt;' => t('The value(s) of the CCK field %fieldname, as defined for your !content_type, comma-separated.', $variables),
    '!cckvalue2_&lt;fieldname&gt;' => t('The value(s) of the CCK field %fieldname, as defined for your !content_type, newline-separated.', $variables),
  );
  return $tokens;
}

/**
 * Implementation of hook_subscriptions_get_mailvars().
 *
 * Add the !cck... variables.
 *
 * @ingroup hooks
 */
function subscriptions_cck_subscriptions_get_mailvars($node) {
  $mailvars = array();
  if (isset($node->type) && ($fields = content_fields(NULL, $node->type))) {
    foreach ($fields as $field_name => $field_info) {
      if (isset($node->{$field_name})) {
        $values = $node->{$field_name};
        $formatteds = array();
        foreach ($values as $value) {
          if (!($formatted = html_entity_decode(content_format($field_info, $value, 'plain'), ENT_QUOTES, 'UTF-8'))) {
            $formatted = content_format($field_info, $value, 'default');
          }
          $formatted = drupal_html_to_text($formatted);
          $formatteds[] = $formatted;
        }
        $mailvars['!ccklabel_' . $field_name] = $field_info['widget']['label'];
        $mailvars['!cckvalue1_' . $field_name] = implode(', ', $formatteds);
        $mailvars['!cckvalue2_' . $field_name] = implode("\n", $formatteds);
      }
    }
  }
  return $mailvars;
}