You are here

entityform_notifications.module in Entityform 7

Same filename and directory in other branches
  1. 7.2 entityform_notifications/entityform_notifications.module

File

entityform_notifications/entityform_notifications.module
View source
<?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;
}