You are here

function commerce_email_form in Commerce Email 7

Implements hook_form().

1 string reference to 'commerce_email_form'
commerce_email_menu in ./commerce_email.module
Implements hook_menu().

File

./commerce_email.module, line 128
Defines additional menu item and order html email functonality.

Code

function commerce_email_form($form, &$form_state) {
  $languages = language_list('enabled');
  $email_list = commerce_email_list_languages($languages[1]);
  drupal_add_library('system', 'ui.tabs');
  drupal_add_js('(function ($) { $(".commerce-email-tabs").tabs(); })(jQuery);', array(
    'type' => 'inline',
    'scope' => 'footer',
    'weight' => 9,
  ));
  $weight = 2;
  $form['settings'] = array(
    '#type' => 'vertical_tabs',
  );
  $form['tokens'] = array(
    '#markup' => theme('token_tree', array(
      'token_types' => array(
        'commerce-order',
        'commerce-customer-profile',
        'commerce-email',
      ),
      '#global_types' => FALSE,
    )),
    '#weight' => 99999,
  );
  foreach ($email_list as $type => $email) {
    foreach ($email as $lang => $e) {

      // Skip language undefined
      if ($lang == LANGUAGE_NONE) {
        continue;
      }
      if (!isset($form[$e->type])) {
        $form[$e->type] = array(
          '#type' => 'fieldset',
          '#title' => check_plain(t(ucwords(str_replace('_', ' ', $e->type)) . ' Email')),
          '#collapsible' => FALSE,
          '#collapsed' => FALSE,
          '#weight' => $weight++,
          '#group' => 'settings',
        );
      }
      $form[$e->type][$e->type . '_subject_' . $lang] = array(
        '#type' => 'textfield',
        '#size' => 128,
        '#maxlength' => 128,
        '#title' => t('Subject'),
        '#default_value' => $e->subject,
        '#required' => TRUE,
        '#weight' => $weight++,
        '#prefix' => '<div id="tabs-' . $lang . '">',
      );
      $form[$e->type][$e->type . '_template_' . $lang] = array(
        '#type' => 'checkbox',
        '#title' => t('Use template instead of textarea'),
        '#default_value' => $e->template ? $e->template : 0,
        '#description' => check_plain('Template: commerce-' . str_replace('_', '-', $e->type) . '-email.tpl.php, commerce-' . str_replace('_', '-', $e->type) . '-email--' . $lang . '.tpl.php'),
        '#weight' => $weight++,
      );
      $form[$e->type][$e->type . '_content_' . $lang] = array(
        '#type' => 'text_format',
        '#cols' => 60,
        '#resizable' => FALSE,
        '#rows' => 10,
        '#title' => t('Content'),
        '#default_value' => $e->content,
        '#required' => TRUE,
        '#weight' => $weight++,
        '#format' => $e->content_format,
      );
      $form[$e->type][$e->type . '_type_' . $lang] = array(
        '#type' => 'hidden',
        '#value' => $e->type,
        '#suffix' => '</div>',
        '#weight' => $weight++,
      );
    }

    /**
     * Language tabs
     */
    $tabs_html = '';
    foreach ($email as $lang => $e) {

      // Skip language undefined
      if ($lang == LANGUAGE_NONE) {
        continue;
      }
      $name = empty($languages[1][$lang]->name) ? 'Language undefined' : $languages[1][$lang]->name;
      $tabs_html .= '<li>' . l($name, '', array(
        'fragment' => 'tabs-' . $lang,
        'external' => TRUE,
      )) . '</a></li>';
    }
    $form[$type]['tabs_start'] = array(
      '#markup' => '<div class="commerce-email-tabs"><ul>' . $tabs_html . '</ul>',
      '#weight' => 1,
    );
    $form[$type]['tabs_end'] = array(
      '#markup' => '</div>',
      '#weight' => $weight++,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 9999,
  );
  return $form;
}