function contact_site_page

Page callback: Presents the site-wide contact form.

Parameters

Drupal\contact\Plugin\Core\Entity\Category $category: (optional) The contact category to use.

Throws

\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException

See also

contact_menu()

contact_site_form_submit()

Related topics

1 string reference to 'contact_site_page'
contact_menu in drupal/core/modules/contact/contact.module
Implements hook_menu().

File

drupal/core/modules/contact/contact.pages.inc, line 25
Page callbacks for the Contact module.

Code

function contact_site_page(Category $category = NULL) {

  // Check if flood control has been activated for sending e-mails.
  if (!user_access('administer contact forms')) {
    contact_flood_control();
  }
  if (!isset($category)) {
    $categories = entity_load_multiple('contact_category');
    $default_category = config('contact.settings')
      ->get('default_category');
    if (isset($categories[$default_category])) {
      $category = $categories[$default_category];
    }
    else {
      if (user_access('administer contact forms')) {
        drupal_set_message(t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array(
          '@add' => url('admin/structure/contact/add'),
        )), 'error');
        return array();
      }
      else {
        throw new NotFoundHttpException();
      }
    }
  }
  $message = entity_create('contact_message', array(
    'category' => $category
      ->id(),
  ));
  return entity_get_form($message);
}