public ContactController::contactPersonalPage(UserInterface $user)
Form constructor for the personal contact form.
Parameters
\Drupal\user\UserInterface $user: The account for which a personal contact form should be generated.
Return value
array The personal contact form as render array as expected by drupal_render().
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Exception is thrown when user tries to access a contact form for a user who does not have an email address configured.
File
- core/modules/contact/src/Controller/ContactController.php, line 103
Class
- ContactController
- Controller routines for contact routes.
Namespace
Drupal\contact\Controller
Code
public function contactPersonalPage(UserInterface $user) {
// Do not continue if the user does not have an email address configured.
if (!$user->getEmail()) {
throw new NotFoundHttpException();
}
$message = $this->entityManager()->getStorage('contact_message')->create(array(
'contact_form' => 'personal',
'recipient' => $user->id(),
));
$form = $this->entityFormBuilder()->getForm($message);
$form['#title'] = $this->t('Contact @username', array('@username' => $user->getDisplayName()));
$form['#cache']['contexts'][] = 'user.permissions';
return $form;
}
Please login to continue.