public function ContactController::contactSitePage in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/contact/src/Controller/ContactController.php \Drupal\contact\Controller\ContactController::contactSitePage()
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.
1 string reference to 'ContactController::contactSitePage'
- 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 61 - Contains \Drupal\contact\Controller\ContactController.
Class
- ContactController
- Controller routines for contact routes.
Namespace
Drupal\contact\ControllerCode
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;
}