You are here

public function ContactController::contactPersonalPage in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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_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 108
Contains \Drupal\contact\Controller\ContactController.

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;
}