subscriptions_cck.module

Tracking 5.x-2.x branch
  1. drupal
    1. 5 contributions/subscriptions/subscriptions_cck.module
    2. 6 contributions/subscriptions/subscriptions_cck.module

Provide support of CCK fields by adding corresponding mailvars.

Functions & methods

NameDescription
subscriptions_cck_form_alterImplementation of hook_form_alter(). Add the !cck_... variable explanation to the Mail Editor forms.
subscriptions_cck_subscriptions_get_mailvarsImplementation of hook_subscriptions_add_mailvars(). Add the !cck... variables.

File

View source
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Provide support of CCK fields by adding corresponding mailvars.
  6. */
  7. /**
  8. * Implementation of hook_form_alter().
  9. * Add the !cck_... variable explanation to the Mail Editor forms.
  10. *
  11. * @ingroup hooks
  12. */
  13. function subscriptions_cck_form_alter($form_id, &$form) {
  14. if ($form_id == 'mail_edit_form' && substr($form['mailkey']['#value'], 0, 13) == 'subscriptions') {
  15. if (!isset($form['addon_help'])) {
  16. $form['addon_help'] = array(
  17. '#variables' => array(),
  18. '#theme' => 'mail_edit_variables',
  19. '#weight' => 35.5,
  20. );
  21. }
  22. $tr = 't';
  23. $variables = array('%fieldname' => '<fieldname>', '!content_type', $tr('content type'));
  24. $form['addon_help']['#variables'] += array(
  25. '!ccklabel_&lt;fieldname&gt;' => t('The label for the CCK field %fieldname, as defined for your !content_type.', $variables),
  26. '!cckvalue1_&lt;fieldname&gt;' => t('The value(s) of the CCK field %fieldname, as defined for your !content_type, comma-separated.', $variables),
  27. '!cckvalue2_&lt;fieldname&gt;' => t('The value(s) of the CCK field %fieldname, as defined for your !content_type, newline-separated.', $variables),
  28. );
  29. }
  30. }
  31. /**
  32. * Implementation of hook_subscriptions_add_mailvars().
  33. * Add the !cck... variables.
  34. *
  35. * @ingroup hooks
  36. */
  37. function subscriptions_cck_subscriptions_get_mailvars($node) {
  38. $mailvars = array();
  39. if (isset($node->type) && ($fields = content_fields(NULL, $node->type))) {
  40. foreach ($fields as $field_name => $field_info) {
  41. if (isset($node->$field_name)) {
  42. $values = $node->$field_name;
  43. $formatteds = array();
  44. foreach ($values as $value) {
  45. if (!($formatted = html_entity_decode( content_format($field_info, $value, 'plain'), ENT_QUOTES, 'UTF-8'))) {
  46. $formatted = content_format($field_info, $value, 'default');
  47. }
  48. $formatteds[] = $formatted;
  49. }
  50. $mailvars['!ccklabel_'. $field_name] = $field_info['widget']['label'];
  51. $mailvars['!cckvalue1_'. $field_name] = implode(', ', $formatteds);
  52. $mailvars['!cckvalue2_'. $field_name] = implode("\n", $formatteds);
  53. }
  54. }
  55. }
  56. return $mailvars;
  57. }