public ContactController::contactSitePage(ContactFormInterface $contact_form = NULL)
Presents the site-wide contact form.
Parameters
\Drupal\contact\ContactFormInterface $contact_form: The contact form to use.
Return value
array The form as render array as expected by drupal_render().
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Exception is thrown when user tries to access non existing default contact form.
File
- core/modules/contact/src/Controller/ContactController.php, line 56
Class
- ContactController
- Controller routines for contact routes.
Namespace
Drupal\contact\Controller
Code
public function contactSitePage(ContactFormInterface $contact_form = NULL) {
$config = $this->config('contact.settings');
// Use the default form if no form has been passed.
if (empty($contact_form)) {
$contact_form = $this->entityManager()
->getStorage('contact_form')
->load($config->get('default_form'));
// If there are no forms, do not display the form.
if (empty($contact_form)) {
if ($this->currentUser()->hasPermission('administer contact forms')) {
drupal_set_message($this->t('The contact form has not been configured. <a href=":add">Add one or more forms</a> .', array(
':add' => $this->url('contact.form_add'))), 'error');
return array();
}
else {
throw new NotFoundHttpException();
}
}
}
$message = $this->entityManager()
->getStorage('contact_message')
->create(array(
'contact_form' => $contact_form->id(),
));
$form = $this->entityFormBuilder()->getForm($message);
$form['#title'] = $contact_form->label();
$form['#cache']['contexts'][] = 'user.permissions';
$this->renderer->addCacheableDependency($form, $config);
return $form;
}
Please login to continue.