function ContactController::contactPersonalPage
Same name in other branches
- 8.9.x core/modules/contact/src/Controller/ContactController.php \Drupal\contact\Controller\ContactController::contactPersonalPage()
- 10 core/modules/contact/src/Controller/ContactController.php \Drupal\contact\Controller\ContactController::contactPersonalPage()
- 11.x core/modules/contact/src/Controller/ContactController.php \Drupal\contact\Controller\ContactController::contactPersonalPage()
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\Core\Render\RendererInterface::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.
1 string reference to 'ContactController::contactPersonalPage'
- contact.routing.yml in core/
modules/ contact/ contact.routing.yml - core/modules/contact/contact.routing.yml
File
-
core/
modules/ contact/ src/ Controller/ ContactController.php, line 107
Class
- ContactController
- Controller routines for contact routes.
Namespace
Drupal\contact\ControllerCode
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->entityTypeManager()
->getStorage('contact_message')
->create([
'contact_form' => 'personal',
'recipient' => $user->id(),
]);
$form = $this->entityFormBuilder()
->getForm($message);
$form['#title'] = $this->t('Contact @username', [
'@username' => $user->getDisplayName(),
]);
$form['#cache']['contexts'][] = 'user.permissions';
return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.