function ContactFormEditForm::form
Same name in other branches
- 8.9.x core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::form()
- 10 core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::form()
- 11.x core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::form()
Overrides EntityForm::form
File
-
core/
modules/ contact/ src/ ContactFormEditForm.php, line 70
Class
- ContactFormEditForm
- Base form for contact form edit forms.
Namespace
Drupal\contactCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$contact_form = $this->entity;
$default_form = $this->config('contact.settings')
->get('default_form');
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $contact_form->label(),
'#description' => $this->t("Example: 'website feedback' or 'product information'."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $contact_form->id(),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#machine_name' => [
'exists' => '\\Drupal\\contact\\Entity\\ContactForm::load',
],
'#disabled' => !$contact_form->isNew(),
];
$form['recipients'] = [
'#type' => 'textarea',
'#title' => $this->t('Recipients'),
'#default_value' => implode(', ', $contact_form->getRecipients()),
'#description' => $this->t("Example: 'webmaster@example.com' or 'sales@example.com,support@example.com' . To specify multiple recipients, separate each email address with a comma."),
'#required' => TRUE,
];
$form['message'] = [
'#type' => 'textarea',
'#title' => $this->t('Message'),
'#default_value' => $contact_form->getMessage(),
'#description' => $this->t('The message to display to the user after submission of this form. Leave blank for no message.'),
];
$form['redirect'] = [
'#type' => 'path',
'#title' => $this->t('Redirect path'),
'#convert_path' => PathElement::CONVERT_NONE,
'#default_value' => $contact_form->getRedirectPath(),
'#description' => $this->t('Path to redirect the user to after submission of this form. For example, type "/about" to redirect to that page. Use a relative path with a slash in front.'),
];
$form['reply'] = [
'#type' => 'textarea',
'#title' => $this->t('Auto-reply'),
'#default_value' => $contact_form->getReply(),
'#description' => $this->t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
];
$form['weight'] = [
'#type' => 'weight',
'#title' => $this->t('Weight'),
'#default_value' => $contact_form->getWeight(),
'#description' => $this->t('When listing forms, those with lighter (smaller) weights get listed before forms with heavier (larger) weights. Forms with equal weights are sorted alphabetically.'),
];
$form['selected'] = [
'#type' => 'checkbox',
'#title' => $this->t('Make this the default form'),
'#default_value' => $default_form === $contact_form->id(),
];
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.