diff --git a/core/modules/contact/contact.admin.inc b/core/modules/contact/contact.admin.inc index 802d3ae..77f4a7e 100644 --- a/core/modules/contact/contact.admin.inc +++ b/core/modules/contact/contact.admin.inc @@ -34,10 +34,6 @@ function contact_category_add() { */ function contact_category_delete_form($form, &$form_state, Category $category) { $form_state['contact_category'] = $category; - $form['id'] = array( - '#type' => 'value', - '#value' => $category->id(), - ); return confirm_form( $form, diff --git a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php index 5ddc2b1..37a1aba 100644 --- a/core/modules/contact/lib/Drupal/contact/CategoryFormController.php +++ b/core/modules/contact/lib/Drupal/contact/CategoryFormController.php @@ -19,19 +19,21 @@ class CategoryFormController extends EntityFormController { * Overrides Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $category) { + $form = parent::form($form, $form_state, $category); + $default_category = config('contact.settings')->get('default_category'); $form['label'] = array( '#type' => 'textfield', '#title' => t('Label'), '#maxlength' => 255, - '#default_value' => $category->label, + '#default_value' => $category->label(), '#description' => t("Example: 'website feedback' or 'product information'."), '#required' => TRUE, ); $form['id'] = array( '#type' => 'machine_name', - '#default_value' => $category->id, + '#default_value' => $category->id(), '#machine_name' => array( 'exists' => 'contact_category_load', 'source' => array('label'), @@ -68,7 +70,7 @@ public function form(array $form, array &$form_state, EntityInterface $category) '#value' => t('Save'), ); - return parent::form($form, $form_state, $category); + return $form; } /** @@ -97,7 +99,7 @@ public function submit(array $form, array &$form_state) { // within the form builder. if ($form_state['triggering_element']['#value'] == t('Delete')) { // Rebuild the form to confirm category deletion. - $form_state['redirect'] = 'admin/structure/contact/delete/' . $form_state['values']['id']; + $form_state['redirect'] = 'admin/structure/contact/manage/' . $form_state['values']['id'] . '/delete'; return NULL; } @@ -109,11 +111,20 @@ public function submit(array $form, array &$form_state) { */ public function save(array $form, array &$form_state) { $category = $this->getEntity($form_state); + // Property enforceIsNew is not supported by config entity. So this is only + // way to make sure that entity is not saved. + $is_new = !$category->getOriginalID(); $category->save(); - $id = $form_state['values']['id']; + $id = $category->id(); - drupal_set_message(t('Category %label has been saved.', array('%label' => $category->label()))); - watchdog('contact', 'Category %label has been saved.', array('%label' => $category->label()), WATCHDOG_NOTICE, l(t('Edit'), 'admin/structure/contact/manage/' . $category->id())); + if ($is_new) { + drupal_set_message(t('Category %label has been added.', array('%label' => $category->label()))); + watchdog('contact', 'Category %label has been added.', array('%label' => $category->label()), WATCHDOG_NOTICE, l(t('Edit'), 'admin/structure/contact/manage/' . $id . '/edit')); + } + else { + drupal_set_message(t('Category %label has been updated.', array('%label' => $category->label()))); + watchdog('contact', 'Category %label has been updated.', array('%label' => $category->label()), WATCHDOG_NOTICE, l(t('Edit'), 'admin/structure/contact/manage/' . $id . '/edit')); + } // Update the default category. $contact_config = config('contact.settings'); diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php index 02eb3ff..14e8d38 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php @@ -79,7 +79,7 @@ function testSiteWideContact() { // Create first valid category. $recipients = array('simpletest@example.com', 'simpletest2@example.com', 'simpletest3@example.com'); $this->addCategory($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE); - $this->assertRaw(t('Category %label has been saved.', array('%label' => $label)), 'Category successfully saved.'); + $this->assertRaw(t('Category %label has been added.', array('%label' => $label)), 'Category successfully added.'); // Make sure the newly created category is included in the list of categories. $this->assertNoUniqueText($label, 'New category included in categories list.'); @@ -91,7 +91,7 @@ function testSiteWideContact() { $this->assertEqual($config['recipients'], array($recipients[0], $recipients[1])); $this->assertEqual($config['reply'], $reply); $this->assertNotEqual($id, config('contact.settings')->get('default_category')); - $this->assertRaw(t('Category %label has been saved.', array('%label' => $label)), 'Category successfully saved.'); + $this->assertRaw(t('Category %label has been updated.', array('%label' => $label)), 'Category successfully updated.'); // Ensure that the contact form is shown without a category selection input. user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form')); @@ -103,10 +103,10 @@ function testSiteWideContact() { // Add more categories. $this->addCategory(drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0], $recipients[1])), '', FALSE); - $this->assertRaw(t('Category %label has been saved.', array('%label' => $label)), 'Category successfully saved.'); + $this->assertRaw(t('Category %label has been added.', array('%label' => $label)), 'Category successfully added.'); $this->addCategory($name = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE); - $this->assertRaw(t('Category %label has been saved.', array('%label' => $label)), 'Category successfully saved.'); + $this->assertRaw(t('Category %label has been added.', array('%label' => $label)), 'Category successfully added.'); // Try adding a category that already exists. $this->addCategory($name, $label, '', '', FALSE);