function mail_edit_trans in Mail Editor 6
1 string reference to 'mail_edit_trans'
- mail_edit_menu in ./
mail_edit.module - Implementation of hook_menu().
File
- ./
mail_edit.admin.inc, line 335 - Administrative interface for the Mail Editor module.
Code
function mail_edit_trans(&$form_status, $id, $lang) {
_mail_edit_include();
$query = "SELECT * FROM {mail_edit_registry} WHERE id = '%s'";
$result = db_query($query, $id);
$mailkey_obj = db_fetch_object($result);
$mailkey = $mailkey_obj->id;
$query = "SELECT * FROM {mail_edit} WHERE id = '%s' AND language = '%s'";
$result = db_query($query, $mailkey, $lang);
// If template is set, then we need to update, if its not set then we need to insert.
$template = db_fetch_object($result);
if ($template) {
$update = TRUE;
}
else {
$update = FALSE;
}
$language = new stdClass();
$language->language = $lang;
$mail_data = module_invoke($mailkey_obj->module, 'mail_edit_text', $mailkey_obj->mailkey, $language);
if (!isset($template->subject)) {
$template->subject = $mail_data['subject'];
}
if (!isset($template->body)) {
$template->body = $mail_data['body'];
}
$variables = array(
'%mailkey' => $mailkey,
'%language' => $lang,
);
if ($update) {
$message = t('Update %mailkey template for %language', $variables);
}
else {
$message = t('Create new %mailkey template for %language', $variables);
}
drupal_set_title($message);
$tokens = array();
$tokens = module_invoke($mailkey_obj->module, 'mail_edit_tokens_list', $mailkey_obj->mailkey);
// Allow other modules to alter tokens for specific mailkey id.
drupal_alter($mailkey_obj->id, $tokens);
$form = array();
$form['update'] = array(
'#type' => 'hidden',
'#value' => $update,
);
$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($mailkey_obj->description) ? filter_xss($mailkey_obj->description, array()) : ''),
);
$form['mail'] = array(
'#type' => 'fieldset',
'#title' => t('Template'),
'#collapsible' => TRUE,
);
$form['mail']['subject'] = array(
'#title' => t('Subject'),
'#type' => 'textfield',
'#default_value' => isset($template->subject) ? $template->subject : '',
);
$form['mail']['body'] = array(
'#title' => t('Body'),
'#type' => 'textarea',
'#default_value' => isset($template->body) ? $template->body : '',
'#rows' => 15,
);
$placeholders = $tokens;
// Display the user documentation of placeholders supported by this module mailkey.
$doc = "<dl>\n";
foreach ($placeholders as $name => $description) {
$doc .= '<dt>' . $name . '</dt>';
$doc .= '<dd>' . $description . '</dd>';
}
$doc .= "</dl>\n";
$form['mail']['token_help'] = array(
'#title' => t('Replacement patterns'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['mail']['token_help']['help'] = array(
'#value' => $doc,
);
$form['op'] = array(
'#type' => 'submit',
'#value' => $update ? t('Update template') : t('Save new template'),
'#submit' => array(
'mail_edit_trans_save',
),
);
if ($update) {
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Remove @language translation', array(
'@language' => $lang,
)),
'#submit' => array(
'mail_edit_trans_delete',
),
);
}
return $form;
}