public function MailEditTemplateForm::buildForm in Mail Editor 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ MailEditTemplateForm.php, line 25
Class
- MailEditTemplateForm
- Edit an email template.
Namespace
Drupal\mail_edit\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $id = NULL, $lang = NULL) {
// Load the template for this object.
$template = $this
->getTemplate($id);
$form['id'] = [
'#type' => 'value',
'#value' => $id,
];
$form['description'] = [
'#markup' => isset($template['description']) ? Xss::filter($template['description']) : '',
'#access' => isset($template['description']),
];
$form['config'] = [
'#title' => $this
->t('Config'),
'#type' => 'textfield',
'#default_value' => $template['config'],
'#disabled' => TRUE,
];
$form['email'] = [
'#title' => $this
->t('Email'),
'#type' => 'textfield',
'#default_value' => $template['name'],
'#disabled' => TRUE,
];
$form['message']['subject'] = [
'#title' => $this
->t('Subject'),
'#type' => 'textfield',
'#default_value' => $template['subject'],
'#maxlength' => 180,
'#required' => TRUE,
];
$form['message']['body'] = [
'#title' => $this
->t('Email body'),
'#type' => 'textarea',
'#default_value' => $template['body'],
'#required' => TRUE,
];
// If the Token module is installed, show a link to the token tree.
$module_handler = \Drupal::moduleHandler();
if ($module_handler
->moduleExists('token')) {
$module_name = $this
->getModuleName($id);
// Trigger hook_mail_edit_token_types().
// The 'user' entity will always be available.
$tokens = [
'user',
] + (array) $module_handler
->invoke($module_name, 'mail_edit_token_types', [
$template['name'],
]);
// Show a link to the token browser.
$form['message']['token_tree'] = [
'#theme' => 'token_tree_link',
'#token_types' => $tokens,
'#show_restricted' => TRUE,
'#show_nested' => FALSE,
];
}
// @todo WYSIWYG support.
// @todo Plaintext support.
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
'#weight' => 10,
];
return $form;
}