diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module
index 7b05c35..1295b66 100644
--- a/core/modules/contact/contact.module
+++ b/core/modules/contact/contact.module
@@ -72,17 +72,24 @@ function contact_menu() {
'weight' => 1,
'file' => 'contact.admin.inc',
);
- $items['admin/structure/contact/manage/%contact_category/edit'] = array(
+ $items['admin/structure/contact/manage/%contact_category'] = array(
'title' => 'Edit contact category',
'page callback' => 'entity_get_form',
'page arguments' => array(4),
'access arguments' => array('administer contact forms'),
);
+ $items['admin/structure/contact/manage/%contact_category/edit'] = array(
+ 'title' => 'Edit',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -10,
+ );
$items['admin/structure/contact/manage/%contact_category/delete'] = array(
- 'title' => 'Delete contact category',
+ 'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('contact_category_delete_form', 4),
'access arguments' => array('administer contact forms'),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 10,
'file' => 'contact.admin.inc',
);
$items['contact'] = array(
@@ -93,6 +100,13 @@ function contact_menu() {
'type' => MENU_SUGGESTED_ITEM,
'file' => 'contact.pages.inc',
);
+ $items['contact/%contact_category'] = array(
+ 'title' => 'Contact',
+ 'page callback' => 'contact_site_page',
+ 'page arguments' => array(1),
+ 'access arguments' => array('access site-wide contact form'),
+ 'file' => 'contact.pages.inc',
+ );
$items['user/%user/contact'] = array(
'title' => 'Contact',
'page callback' => 'contact_personal_page',
diff --git a/core/modules/contact/contact.pages.inc b/core/modules/contact/contact.pages.inc
index 0b9217b..581a4cd 100644
--- a/core/modules/contact/contact.pages.inc
+++ b/core/modules/contact/contact.pages.inc
@@ -5,12 +5,16 @@
* Page callbacks for the Contact module.
*/
+use Drupal\contact\Category;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Page callback: Presents the site-wide contact form.
*
+ * @param \Drupal\contact\Category $category
+ * (optional) The contact category to use.
+ *
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*
@@ -18,26 +22,30 @@
* @see contact_site_form_submit()
* @ingroup forms
*/
-function contact_site_page() {
+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();
}
// Get an array of the categories and the current default category.
- $categories = entity_load_multiple('contact_category');
- // If there are no categories, do not display the form.
- if (!$categories) {
- if (user_access('administer contact forms')) {
- drupal_set_message(t('The contact form has not been configured. Add one or more categories to the form.', array('@add' => url('admin/structure/contact/add'))), 'error');
- }
- else {
- throw new NotFoundHttpException();
+ if (!isset($category)) {
+ $categories = entity_load_multiple('contact_category');
+ // If there are no categories, do not display the form.
+ if (!$categories) {
+ if (user_access('administer contact forms')) {
+ drupal_set_message(t('The contact form has not been configured. Add one or more categories to the form.', array('@add' => url('admin/structure/contact/add'))), 'error');
+ }
+ else {
+ throw new NotFoundHttpException();
+ }
}
}
// @todo Separate forms per category?
// @todo Add 'uid' or 'sender' property and set property here?
- $message = entity_create('contact_message', array());
+ $message = entity_create('contact_message', array(
+ 'category' => isset($category) ? $category->id() : NULL,
+ ));
return entity_get_form($message);
}
diff --git a/core/modules/contact/lib/Drupal/contact/Message.php b/core/modules/contact/lib/Drupal/contact/Message.php
index 241fad0..03562b1 100644
--- a/core/modules/contact/lib/Drupal/contact/Message.php
+++ b/core/modules/contact/lib/Drupal/contact/Message.php
@@ -15,7 +15,7 @@
class Message extends Entity {
/**
- * The category ID of this message.
+ * The contact category ID of this message.
*
* @var string
*/
@@ -76,4 +76,11 @@ class Message extends Entity {
*/
public $copy;
+ /**
+ * Overrides Drupal\Core\Entity\Entity::bundle().
+ */
+ public function bundle() {
+ return $this->category;
+ }
+
}
diff --git a/core/modules/contact/lib/Drupal/contact/MessageFormController.php b/core/modules/contact/lib/Drupal/contact/MessageFormController.php
index dac2d81..d56e421 100644
--- a/core/modules/contact/lib/Drupal/contact/MessageFormController.php
+++ b/core/modules/contact/lib/Drupal/contact/MessageFormController.php
@@ -63,6 +63,12 @@ public function form(array $form, array &$form_state, EntityInterface $message)
),
);
}
+ elseif (!empty($message->category)) {
+ $form['category'] = array(
+ '#type' => 'value',
+ '#value' => $message->category,
+ );
+ }
else {
// Prepare array for select options.
$categories = entity_load_multiple('contact_category');
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index 7fac3d2..09eee0f 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -1300,7 +1300,9 @@ function theme_field($variables) {
function _field_create_entity_from_ids($ids) {
$id_properties = array();
$info = entity_get_info($ids->entity_type);
- $id_properties[$info['entity keys']['id']] = $ids->entity_id;
+ if (isset($info['entity keys']['id'])) {
+ $id_properties[$info['entity keys']['id']] = $ids->entity_id;
+ }
if (!empty($info['entity keys']['revision']) && isset($ids->revision_id)) {
$id_properties[$info['entity keys']['revision']] = $ids->revision_id;
}