public function ContactForm::buildForm in Email Contact 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/ ContactForm.php, line 38
Class
Namespace
Drupal\email_contact\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// $this->entity_id = $id;
$user = \Drupal::currentUser();
$emails = email_contact_get_emails_from_field($this->entity_type, $this->entity_id, $this->field_name);
$form['emails'] = array(
'#type' => 'value',
'#value' => serialize($emails),
);
$form['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Your name'),
'#maxlength' => 255,
'#default_value' => $user
->id() ? $user
->getDisplayName() : '',
'#required' => TRUE,
];
$form['mail'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Your e-mail address'),
'#maxlength' => 255,
'#default_value' => $user
->id() ? $user
->getEmail() : '',
'#required' => TRUE,
);
$form['subject'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Subject'),
'#maxlength' => 255,
'#required' => TRUE,
);
$form['message'] = array(
'#type' => 'textarea',
'#title' => $this
->t('Message'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Send e-mail'),
);
if (!$form_state
->get('settings')) {
$form_state
->set('settings', $this->field_settings);
}
return $form;
}