You are here

function mail_edit_template_subform in Mail Editor 7

Prepare a template edit subform.

Parameters

array $template: An array with optional 'subject' and 'body' keys, containing the current subject and body strings.

Return value

array

1 call to mail_edit_template_subform()
mail_edit_template_form in ./mail_edit.admin.inc
Form builder function to prepare the template edit form.

File

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

Code

function mail_edit_template_subform($template) {

  //dpm($template, "mail_edit_template_subform");
  $form = array(
    '#type' => 'fieldset',
    '#title' => t('Template'),
    '#collapsible' => FALSE,
  );
  if (isset($template['subject'])) {
    $form['subject'] = array(
      '#title' => t('Subject'),
      '#type' => 'textarea',
      '#default_value' => $template['subject'],
      '#rows' => 1,
      '#description' => t("Subject must expand into a single line; it's a multiline field for editing convenience only."),
    );
  }
  if (isset($template['body'])) {
    $form['body'] = array(
      '#title' => t('Body'),
      '#type' => 'textarea',
      '#default_value' => $template['body'],
      '#rows' => 15,
    );
  }
  if (module_exists('token')) {
    $token_types = module_invoke($template['type']['module'], 'mail_edit_token_types', $template['type']['id']);
    $form['token_tree'] = array(
      '#theme' => 'token_tree',
      '#token_types' => empty($token_types) ? array() : $token_types,
      '#show_restricted' => $template['type']['module'] == 'user',
      '#weight' => 10,
      '#dialog' => TRUE,
    );
    drupal_add_css(drupal_get_path('module', 'mail_edit') . '/mail_edit.admin.css');
  }
  else {
    $form['token_tree'] = array(
      '#markup' => '<p>' . t('Enable the <a href="@drupal-token">Token module</a> to view the available tokens.', array(
        '@drupal-token' => 'https://www.drupal.org/project/token',
      )) . '</p>',
    );
  }
  $form['dynamic'] = array(
    '#type' => 'fieldset',
    '#title' => t('Dynamic text information'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 15,
  );
  $form['dynamic'][] = array(
    '#markup' => t('Dynamic text provides a way to dynamically adapt templates based on comparisons with token values.') . '<br />' . t('Note: Be careful about spaces and line breaks &mdash; they do count!') . '<div>' . '<div style="font-size: 4ex; margin-top: 1em"><b style="color: red">{{</b><u>left</u>&lt;&gt;<u>right</u><b style="color: red">?</b><u>true_text</u><b style="color: red">:</b><u>false_text</u><b style="color: red">}}</b></div><br />' . '<div style="font-size: 4ex"><b style="color: red">{{</b><u>condition</u><b style="color: red">?</b><u>true_text</u><b style="color: red">:</b><u>false_text</u><b style="color: red">}}</b></div><br />' . '<dl style="margin-bottom: 0">' . '<dt>' . t('!left and !right', array(
      '!left' => '<u>left</u>',
      '!right' => '<u>right</u>',
    )) . '</dt><dd style="margin-bottom: 0">' . t("Any text (including nothing), which may also contain tokens but no question marks (@qm) or comparison operators.", array(
      '@qm' => "'?'",
    )) . '</dd><br />' . '<dt>&lt;&gt;</dt><dd style="margin-bottom: 0">' . t('Any of the common comparison operators (@list).', array(
      '@list' => "'==', '!=', '>', '<', '>=', '<='",
    )) . '</dd><br />' . '<dt><u>condition</u></dt><dd style="margin-bottom: 0">' . t('A token; the @condition is false if the token evaluates to empty or 0, true otherwise. A prepended exclamation mark (!excl) reverses the logic.', array(
      '@condition' => 'condition',
      '!excl' => "'!'",
    )) . '</dd><br />' . '<dt><u>true_text</u></dt><dd style="margin-bottom: 0">' . t("Any text (including nothing), but no colon (@colon), except inside token names or nested dynamic clauses.<br />Square brackets (@brackets) must match and cannot be nested.", array(
      '@colon' => "':'",
      '@brackets' => "'[', ']'",
    )) . '</dd><br />' . '<dt><u>false_text</u></dt><dd style="margin-bottom: 0">' . t("Any text (including nothing).") . '</dd><br />' . '</dl>' . t('If the comparison evaluates to true, then !true_text is used, otherwise !false_text.', array(
      '!true_text' => '<u>true_text</u>',
      '!false_text' => '<u>false_text</u>',
    )) . '<br />' . '</div>' . '<div>' . '<div style="font-size: 4ex; margin-top: 1em"><b style="color: red">{{</b><u>count</u><b style="color: red">#</b><u>repeated_text</u><b style="color: red">}}</b></div><br />' . '<dl style="margin-bottom: 0">' . '<dt><u>count</u></dt><dd style="margin-bottom: 0">' . t('A number or token that evaluates to a number. A prepended exclamation mark (!excl) turns 0 into 1 and anything else into 0; two prepended exclamation marks (!two_excl) keep 0 and turn anything else into 1.', array(
      '!excl' => "'!'",
      '!two_excl' => "'!!'",
    )) . '</dd><br />' . '<dt><u>repeated_text</u></dt><dd style="margin-bottom: 0">' . t("The text that is to be repeated !count times. The text can include !number0 and !number1 which will be replaced by the 0- or 1-based index of the current iteration; the former can be used for indexing array tokens, i.e. !example, the latter for numbering the items starting at 1, as the end user would expect.", array(
      '!count' => '<u>count</u>',
      '!number0' => "'#0'",
      '!number1' => "'#1'",
      '!example' => "'[<u>array</u><span style='color: red'>:index:#0</span>:<u>whatever</u>]'",
    )) . '<br />' . t('Example: the following code lists the roles and rids (role keys) of the user, one per line:') . '<br />' . '<code>{{[user:roles:count]# &nbsp; #1: [user:roles:index:#0] ([user:roles:keys:value:#0])<br />}}</code>' . '</dd><br />' . '</dl>' . '</div>' . '<div>' . '<div style="font-size: 4ex; margin-top: 0.5em"><b style="color: red">{{</b><u>context</u><b style="color: red">@</b><u>conditional_text</u><b style="color: red">}}</b></div><br />' . '<dl style="margin-bottom: 0">' . '<dt><u>context</u></dt><dd style="margin-bottom: 0">' . t('A string that is passed in to discern the context of applying the template. A prepended exclamation mark (!excl) reverses the logic.', array(
      '!excl' => "'!'",
    )) . '<br />' . t('If the resulting text is used as a mail message, then the context is !MAIL. Client modules can pass in different context strings to get templates filled in for other purposes.', array(
      '!MAIL' => "'MAIL'",
    )) . '</dd><br />' . '<dt><u>conditional_text</u></dt><dd style="margin-bottom: 0">' . t("The text that is to be used in the given context, or in every other context if the exclamation mark (!excl) is used. This construct supports an additional level of nesting.", array(
      '!count' => '<u>count</u>',
      '!number0' => "'#0'",
      '!number1' => "'#1'",
      '!excl' => "'!'",
    )) . '</dd><br />' . '</dl>' . '</div>' . '<p>' . t('The replacement texts can contain line breaks and tokens, and they support four levels of nesting.') . '</p>' . '<p>' . t("As an extension to Drupal's token system, !Mail_Editor adds support for spaces and newlines inside the separator string of !join tokens.", array(
      '!Mail_Editor' => 'Mail Editor',
      '!join' => '[*:join:?]',
    )) . '</p>',
  );
  return $form;
}