You are here

function mail_edit_template_form in Mail Editor 7

Form builder function to prepare the template edit form.

_state

Parameters

array $form:

string $id:

string $lang:

Return value

array

1 string reference to 'mail_edit_template_form'
mail_edit_menu in ./mail_edit.module
Implements hook_menu().

File

./mail_edit.admin.inc, line 361
Administrative interface for the Mail Editor module.

Code

function mail_edit_template_form(array $form, array $form_state, $id, $lang) {
  _mail_edit_include();
  _mail_edit_module_load_include('alter.inc');
  $template = _mail_edit_load($id, $lang, TRUE);
  if ($template === FALSE) {
    drupal_not_found();
    drupal_exit();
  }
  $new = !empty($template['default']);
  $language_list = mail_edit_language_list();
  $variables = array(
    '%mailkey' => $template['type']['mailkey'],
    '%language' => $language_list[$lang],
  );
  if (count($language_list) > 1) {
    $message = t($new ? 'Create new %mailkey template for %language' : 'Update %mailkey template for %language', $variables);
  }
  else {
    $message = t($new ? 'Create new %mailkey template' : 'Update %mailkey template', $variables);
  }
  $dst = 'drupal_set_title';

  // Keep Coder happy.
  $dst($message, PASS_THROUGH);
  $form = array();
  $form['update'] = array(
    '#type' => 'hidden',
    '#value' => !$new,
  );
  $form['language'] = array(
    '#type' => 'hidden',
    '#value' => $lang,
  );
  $form['id'] = array(
    '#type' => 'hidden',
    '#value' => $id,
  );
  $form['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textfield',
    '#default_value' => isset($template['description']) ? $template['description'] : (isset($template['type']['description']) ? filter_xss($template['type']['description'], array()) : ''),
    '#size' => 100,
    '#weight' => -10,
  );
  $form['mail'] = mail_edit_template_subform($template);
  $form['op'] = array(
    '#type' => 'submit',
    '#value' => $new ? t('Save new template') : t('Update template'),
    '#submit' => array(
      'mail_edit_template_form_save',
    ),
    '#weight' => 10,
  );
  if (!$new) {
    $form['remove'] = array(
      '#type' => 'submit',
      '#value' => count($language_list) > 1 ? t('Remove @language template', array(
        '@language' => $language_list[$lang],
      )) : t('Remove template'),
      '#submit' => array(
        'mail_edit_template_form_remove',
      ),
      '#weight' => 20,
    );
  }
  $extra_func = $template['type']['module'] . '_mail_edit_form_extra';
  if (function_exists($extra_func)) {
    $extra_func($form, $form_state, $template['type']['mailkey'], $template);
  }
  return $form;
}