Commit 1aa842c1 authored by catch's avatar catch

Issue #1946366 by kim.pepper: Convert confirm_form() in contact.admin.inc to...

Issue #1946366 by kim.pepper: Convert confirm_form() in contact.admin.inc to the new form interface.
parent c71dc213
......@@ -51,43 +51,3 @@ function contact_category_edit(Category $category) {
drupal_set_title(t('Edit %label contact form category', array('%label' => $category->label())), PASS_THROUGH);
return entity_get_form($category);
}
/**
* Page callback: Form constructor for the contact category deletion form.
*
* @param Drupal\contact\Plugin\Core\Entity\Category $category
* The contact category to be deleted.
*
* @see contact_menu()
* @see contact_category_delete_form_submit()
*
* @ingroup forms
*/
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,
t('Are you sure you want to delete %label?', array('%label' => $category->label())),
'admin/structure/contact',
t('This action cannot be undone.'),
t('Delete')
);
}
/**
* Form submission handler for contact_category_delete_form().
*/
function contact_category_delete_form_submit($form, &$form_state) {
$category = $form_state['contact_category'];
$category->delete();
drupal_set_message(t('Category %label has been deleted.', array('%label' => $category->label())));
watchdog('contact', 'Category %label has been deleted.', array('%label' => $category->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/contact';
}
......@@ -87,12 +87,9 @@ function contact_menu() {
);
$items['admin/structure/contact/manage/%contact_category/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('contact_category_delete_form', 4),
'access arguments' => array('administer contact forms'),
'route_name' => 'contact_category_delete',
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'contact.admin.inc',
);
$items['contact'] = array(
......
contact_category_delete:
pattern: 'admin/structure/contact/manage/{contact_category}/delete'
defaults:
_form: '\Drupal\contact\Form\DeleteForm'
requirements:
_permission: 'administer contact forms'
<?php
/**
* @file
* Contains \Drupal\contact\Form\DeleteForm.
*/
namespace Drupal\contact\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\contact\Plugin\Core\Entity\Category;
/**
* Builds the form to delete a contact category.
*/
class DeleteForm extends ConfirmFormBase {
/**
* The contact category being deleted.
*
* @var \Drupal\contact\Plugin\Core\Entity\Category
*/
protected $contactCategory;
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'contact_category_delete_form';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
*/
protected function getQuestion() {
return t('Are you sure you want to delete %name?', array('%name' => $this->contactCategory->label()));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
*/
protected function getCancelPath() {
return 'admin/structure/contact';
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm().
*/
public function buildForm(array $form, array &$form_state, Category $contact_category = NULL) {
$this->contactCategory = $contact_category;
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->contactCategory->delete();
drupal_set_message(t('Category %label has been deleted.', array('%label' => $this->contactCategory->label())));
watchdog('contact', 'Category %label has been deleted.', array('%label' => $this->contactCategory->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/contact';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment