summaryrefslogtreecommitdiffstats
path: root/entityform_notifications/entityform_notifications.module
blob: 37dee79e57b8e83204538cb79f96a585909b0e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

/**
 * Implements hook_form_FORM_ID_alter().
 */
function entityform_notifications_form_entityform_settings_alter(&$form, &$form_state, $form_id) {
  $entityform_type = $form['#entityform_type'];
  _entityform_notifications_type_settings($form['entityform_type_defaults']['data']['notifications_set'], $entityform_type);
  //$form['entityform_type_defaults']['data']['notifications_set'] = $notifications_set;
  _entityform_remove_fieldsets_from_tree($form['entityform_type_defaults']['data'], array('entityform_type_defaults', 'data'));
}
/**
 * Implements hook_form_FORM_ID_alter()
 */
function entityform_notifications_form_variable_edit_form_alter(&$form, &$form_state) {
  $variable_id = is_array($form_state['build_info']['args'][0]) ? $form_state['build_info']['args'][0][0] : $form_state['build_info']['args'][0];
  if (substr($variable_id, 0, 11) == 'entityform_') {
    $form['tokens'] = array(
        '#markup' => theme('token_tree', array('token_types' => array('entityform'), 'global_types' => FALSE)),
        '#weight' => 99999
    );
  }
}
/**
 * Implements hook_form_FORM_ID_alter().
 */
function entityform_notifications_form_entityform_type_form_alter(&$form, &$form_state, $form_id) {
  $entityform_type = $form['#entityform_type'];
  _entityform_notifications_type_settings($form['data']['notifications_set'], $entityform_type);
  //$form['data'] ['notifications_set'] = $notifications_set;
  _entityform_remove_fieldsets_from_tree($form['data'], array('data'));

}
function _entityform_notifications_type_settings(&$notifications_fieldset, $entityform_type) {
  //****************NOTIFICATIONS FIELDSET SETTINGS *********************//
  $notifications_fieldset['notification_text'] = array(
      '#type' => 'textarea',
      '#title' => t('Email text'),
      '#default_value' => empty($entityform_type->data['notification_text']) ? '' : $entityform_type->data['notification_text'],
      '#description' => t('Text for Confirmation Email to submitter. DO NOT put HTML in this field'),
      '#weight' => 70,
  );
  $notifications_fieldset['notify_emails'] = array(
      '#type' => 'textfield',
      '#title' => t('Notification emails'),
      '#default_value' => empty($entityform_type->data['notify_emails']) ? '' : $entityform_type->data['notify_emails'],
      '#description' => t('Enter emails that should be notified for each form submissions.'),
      '#element_validate' => array('_entityform_form_email_list_validate'),
      '#weight' => 80,
  );
  if (!module_exists('variable_admin')) {
    //Inform user to enable this module
    $notifications_fieldset['notify_help'] = array(
      '#type' => 'markup',
      '#markup' => t('Enable the %module module to edit the full body and subject of these emails', array('%module' => 'Variable admin')),
      '#weight' => 60,
    );
  }
  else {
    $variable_path = 'admin/config/system/variable/edit/entityform_notify_';
    $text = t('Edit the subject and body of this email');
    $attributes = array('query' => array('destination' => current_path()));
    $notifications_fieldset['notification_text']['#description'] .= ' ' . l($text,$variable_path . 'submitter_[mail_part]', $attributes);
    $notifications_fieldset['notify_emails']['#description'] .= ' ' . l($text,$variable_path . 'admin_[mail_part]', $attributes);
  }
  //return $notifications_set;
}