diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index d0d59fd..1ce5e1c 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -49,9 +49,7 @@ function config_test_menu() { ); $items['admin/structure/config_test/manage/%config_test/delete'] = array( 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('config_test_delete_form', 4), - 'access callback' => TRUE, + 'route_name' => 'config_test_delete', 'type' => MENU_LOCAL_TASK, ); $items['admin/structure/config_test/manage/%config_test/enable'] = array( @@ -114,33 +112,6 @@ function config_test_edit_page(ConfigTest $config_test) { } /** - * Form constructor to delete a ConfigTest object. - * - * @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test - * The ConfigTest object to delete. - */ -function config_test_delete_form($form, &$form_state, ConfigTest $config_test) { - $form_state['config_test'] = $config_test; - - $form['id'] = array('#type' => 'value', '#value' => $config_test->id()); - return confirm_form($form, - format_string('Are you sure you want to delete %label', array('%label' => $config_test->label())), - 'admin/structure/config_test', - NULL, - 'Delete' - ); -} - -/** - * Form submission handler for config_test_delete_form(). - */ -function config_test_delete_form_submit($form, &$form_state) { - $form_state['config_test']->delete(); - drupal_set_message(format_string('%label configuration has been deleted.', array('%label' => $form_state['config_test']->label()))); - $form_state['redirect'] = 'admin/structure/config_test'; -} - -/** * Implements hook_cache_flush(). */ function config_test_cache_flush() { diff --git a/core/modules/config/tests/config_test/config_test.routing.yml b/core/modules/config/tests/config_test/config_test.routing.yml new file mode 100644 index 0000000..92bb0a9 --- /dev/null +++ b/core/modules/config/tests/config_test/config_test.routing.yml @@ -0,0 +1,6 @@ +config_test_delete: + pattern: 'admin/structure/config_test/manage/{config_test}/delete' + defaults: + _form: '\Drupal\config_test\ConfigTestDeleteForm' + requirements: + _access: 'TRUE' diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestDeleteForm.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestDeleteForm.php new file mode 100644 index 0000000..e1ad7f2 --- /dev/null +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestDeleteForm.php @@ -0,0 +1,76 @@ + $this->configTest->label())); + } + + /** + * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). + */ + protected function getCancelPath() { + return 'admin/structure/config_test'; + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText(). + */ + protected function getConfirmText() { + return t('Delete'); + } + + /** + * Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm(). + * + * @param \Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test + * (optional) The ConfigTest object to delete. If NULL, your form is + * probably broken, but the interface gets pissy otherwise. + */ + public function buildForm(array $form, array &$form_state, ConfigTest $config_test = NULL) { + $this->configTest = $config_test; + return parent::buildForm($form, $form_state); + } + + /** + * Implements \Drupal\Core\Form\FormInterface::submitForm(). + */ + public function submitForm(array &$form, array &$form_state) { + $label = $this->configTest->label(); + $this->configTest->delete(); + drupal_set_message(format_string('%label configuration has been deleted.', array('%label' => $label))); + return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE))); + } + +} +