Overrides Drupal\Core\Entity\EntityFormController::form().
Overrides EntityFormController::form
public function form(array $form, array &$form_state) {
global $user;
$message = $this->entity;
$form = parent::form($form, $form_state, $message);
$form['#attributes']['class'][] = 'contact-form';
if (!empty($message->preview)) {
$form['preview'] = array(
'#theme_wrappers' => array(
'container__preview',
),
'#attributes' => array(
'class' => array(
'preview',
),
),
);
$form['preview']['message'] = entity_view($message, 'full');
}
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 255,
'#required' => TRUE,
);
$form['mail'] = array(
'#type' => 'email',
'#title' => t('Your e-mail address'),
'#required' => TRUE,
);
if (!$user->uid) {
$form['#attached']['library'][] = array(
'system',
'jquery.cookie',
);
$form['#attributes']['class'][] = 'user-info-from-cookie';
}
else {
$form['name']['#type'] = 'item';
$form['name']['#value'] = $user->name;
$form['name']['#required'] = FALSE;
$form['name']['#markup'] = check_plain(user_format_name($user));
$form['mail']['#type'] = 'item';
$form['mail']['#value'] = $user->mail;
$form['mail']['#required'] = FALSE;
$form['mail']['#markup'] = check_plain($user->mail);
}
// The user contact form has a preset recipient.
if ($message
->isPersonal()) {
$form['recipient'] = array(
'#type' => 'item',
'#title' => t('To'),
'#value' => $message->recipient,
'name' => array(
'#theme' => 'username',
'#account' => $message->recipient,
),
);
}
else {
$form['category'] = array(
'#type' => 'value',
'#value' => $message->category,
);
}
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 100,
'#required' => TRUE,
);
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#required' => TRUE,
'#rows' => 12,
);
$form['copy'] = array(
'#type' => 'checkbox',
'#title' => t('Send yourself a copy.'),
// Do not allow anonymous users to send themselves a copy, because it can
// be abused to spam people.
'#access' => !empty($user->uid),
);
return $form;
}