public function WebformEmailReplyForm::buildForm in Webform Email Reply 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/ WebformEmailReplyForm.php, line 100 - Contains \Drupal\webform_email_reply\Form\WebformEmailReplyForm.
Class
Namespace
Drupal\webform_email_reply\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $node = NULL, WebformSubmissionInterface $webform_submission = NULL) {
$this->webformSubmission = $webform_submission;
// Prepopulate values.
$user = $this->currentUser;
$default_from_email = \Drupal::config('system.site')
->get('mail');
$title = $webform_submission
->getWebform()
->label();
$webform_id = $webform_submission
->getWebform()
->id();
$sid = $webform_submission
->id();
// Only display link if there are replies.
$replies = webform_email_reply_get_replies($webform_id, $sid);
$replies_count = count($replies);
if ($replies_count) {
$form['previous_replies'] = [
'#type' => 'link',
'#title' => \Drupal::translation()
->formatPlural($replies_count, '1 previous reply', '@count previous replies'),
'#url' => Url::fromRoute('webform_email_reply.previous', [
'webform' => $webform_id,
'webform_submission' => $sid,
]),
];
}
$form['#tree'] = TRUE;
$form['details']['webform_id'] = [
'#type' => 'value',
'#value' => $webform_id,
];
$form['details']['sid'] = [
'#type' => 'value',
'#value' => $sid,
];
$form['details']['from_address'] = [
'#type' => 'textfield',
'#title' => $this
->t('From'),
'#default_value' => $default_from_email,
'#description' => $this
->t('The email address to send from.'),
'#required' => TRUE,
];
$form['details']['email'] = [
'#type' => 'textfield',
'#title' => $this
->t('Email'),
'#description' => $this
->t('The email address(es) to send to. Multiple emails should be separated by a comma, with no spaces.'),
'#required' => TRUE,
];
$form['details']['subject'] = [
'#type' => 'textfield',
'#title' => $this
->t('Subject'),
'#default_value' => $this
->t('RE: @title', [
'@title' => strip_tags($title),
]),
'#required' => TRUE,
];
$form['details']['message'] = [
'#type' => 'webform_html_editor',
'#title' => $this
->t('Message'),
'#required' => TRUE,
];
$form['details']['attachement'] = [
'#type' => 'managed_file',
'#title' => $this
->t("Attachment"),
'#upload_location' => 'public://webform_email_reply/',
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Send'),
];
// Add submission navigation.
$source_entity = $this->requestHandler
->getCurrentSourceEntity('webform_submission');
$form['navigation'] = [
'#type' => 'webform_submission_navigation',
'#webform_submission' => $webform_submission,
'#weight' => -20,
];
$form['information'] = [
'#type' => 'webform_submission_information',
'#webform_submission' => $webform_submission,
'#source_entity' => $source_entity,
'#weight' => -19,
];
$form['#attached']['library'][] = 'webform/webform.admin';
$form['#attached']['library'][] = 'webform/webform.element.html_editor';
return $form;
}