diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index 84fbc97..af1453a 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -223,7 +223,7 @@ function testCRUDUI() { $edit = array( 'label' => $label2, ); - $this->drupalPost("admin/structure/config_test/manage/$id", $edit, 'Save'); + $this->drupalPost("admin/structure/config_test/manage/$id/edit", $edit, 'Save'); $this->assertUrl('admin/structure/config_test'); $this->assertResponse(200); $this->assertNoRaw($message_insert); @@ -241,7 +241,6 @@ function testCRUDUI() { $this->assertNoRaw($message_update); $this->assertRaw($message_delete); $this->assertNoText($label1); - $this->assertNoLinkByHref("admin/structure/config_test/manage/$id"); $this->assertNoLinkByHref("admin/structure/config_test/manage/$id/edit"); // Re-create a configuration entity. @@ -260,13 +259,12 @@ function testCRUDUI() { 'id' => strtolower($this->randomName()), 'label' => $label3, ); - $this->drupalPost("admin/structure/config_test/manage/$id", $edit, 'Save'); + $this->drupalPost("admin/structure/config_test/manage/$id/edit", $edit, 'Save'); $this->assertUrl('admin/structure/config_test'); $this->assertResponse(200); $this->assertNoText($label1); $this->assertNoText($label2); $this->assertText($label3); - $this->assertNoLinkByHref("admin/structure/config_test/manage/$id"); $this->assertNoLinkByHref("admin/structure/config_test/manage/$id/edit"); $id = $edit['id']; $this->assertLinkByHref("admin/structure/config_test/manage/$id/edit"); diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index c2c004c..d7dd961 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -32,38 +32,24 @@ function config_test_menu() { ); $items['admin/structure/config_test/add'] = array( 'title' => 'Add test configuration', - 'page callback' => 'config_test_add_page', - 'access callback' => TRUE, + 'route_name' => 'config_test_entity_add', 'type' => MENU_LOCAL_ACTION, ); - $items['admin/structure/config_test/manage/%config_test'] = array( - 'title' => 'Edit test configuration', - 'page callback' => 'config_test_edit_page', - 'page arguments' => array(4), - 'access callback' => TRUE, - ); $items['admin/structure/config_test/manage/%config_test/edit'] = array( 'title' => 'Edit', - 'type' => MENU_DEFAULT_LOCAL_TASK, + 'route_name' => 'config_test_entity_edit', ); $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, - 'type' => MENU_LOCAL_TASK, + 'route_name' => 'config_test_entity_delete', ); $items['admin/structure/config_test/manage/%config_test/enable'] = array( 'title' => 'Enable', - 'page callback' => 'config_test_entity_enable', - 'page arguments' => array(4), - 'access callback' => TRUE, + 'route_name' => 'config_test_entity_enable', ); $items['admin/structure/config_test/manage/%config_test/disable'] = array( 'title' => 'Disable', - 'page callback' => 'config_test_entity_disable', - 'page arguments' => array(4), - 'access callback' => TRUE, + 'route_name' => 'config_test_entity_disable', ); return $items; } @@ -79,58 +65,6 @@ function config_test_load($id) { } /** - * Page callback: Presents the ConfigTest creation form. - * - * @return array - * A form array as expected by drupal_render(). - */ -function config_test_add_page() { - $entity = entity_create('config_test', array()); - return entity_get_form($entity); -} - -/** - * Page callback: Presents the ConfigTest edit form. - * - * @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test - * The ConfigTest object to edit. - * - * @return array - * A form array as expected by drupal_render(). - */ -function config_test_edit_page(ConfigTest $config_test) { - drupal_set_title(format_string('Edit %label', array('%label' => $config_test->label())), PASS_THROUGH); - return entity_get_form($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() { @@ -148,32 +82,6 @@ function config_test_config_test_create(ConfigTest $config_test) { } /** - * Enables a ConfigTest object. - * - * @param Drupal\config_test\ConfigTest $config_test - * The ConfigTest object to enable. - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse. - */ -function config_test_entity_enable(ConfigTest $config_test) { - $config_test->enable()->save(); - return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE))); -} - -/** - * Disables a ConfigTest object. - * - * @param Drupal\config_test\ConfigTest $config_test - * The ConfigTest object to disable. - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse. - */ -function config_test_entity_disable(ConfigTest $config_test) { - $config_test->disable()->save(); - return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE))); -} - -/** * Implements hook_entity_info_alter(). */ function config_test_entity_info_alter(&$entity_info) { diff --git a/core/modules/config/tests/config_test/config_test.routing.yml b/core/modules/config/tests/config_test/config_test.routing.yml index d939b30..b95aa91 100644 --- a/core/modules/config/tests/config_test/config_test.routing.yml +++ b/core/modules/config/tests/config_test/config_test.routing.yml @@ -5,3 +5,42 @@ config_test_list_page: entity_type: 'config_test' requirements: _access: 'TRUE' + +config_test_entity_add: + pattern: 'admin/structure/config_test/add' + defaults: + _entity_form: 'config_test' + requirements: + _access: 'TRUE' + +config_test_entity_edit: + pattern: 'admin/structure/config_test/manage/{config_test}/edit' + defaults: + _controller: '\Drupal\config_test\ConfigTestController::edit' + entity_type: 'config_test' + requirements: + _access: 'TRUE' + +config_test_entity_enable: + pattern: 'admin/structure/config_test/manage/{config_test}/enable' + defaults: + _content: '\Drupal\config_test\ConfigTestController::enable' + entity_type: 'config_test' + requirements: + _access: 'TRUE' + +config_test_entity_disable: + pattern: 'admin/structure/config_test/manage/{config_test}/disable' + defaults: + _content: '\Drupal\config_test\ConfigTestController::disable' + entity_type: 'config_test' + requirements: + _access: 'TRUE' + +config_test_entity_delete: + pattern: 'admin/structure/config_test/manage/{config_test}/delete' + defaults: + _form: '\Drupal\config_test\Form\DeleteForm' + entity_type: 'config_test' + requirements: + _access: 'TRUE' diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php new file mode 100644 index 0000000..4bdf220 --- /dev/null +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php @@ -0,0 +1,84 @@ +entityManager = $entity_manager; + } + + /** + * {inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static($container->get('plugin.manager.entity')); + } + + /** + * Page callback: Presents the ConfigTest edit form. + * + * @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test + * The ConfigTest object to edit. + * + * @return array + * A form array as expected by drupal_render(). + */ + public function edit(ConfigTest $config_test) { + drupal_set_title(format_string('Edit %label', array('%label' => $config_test->label())), PASS_THROUGH); + return entity_get_form($config_test); + } + + /** + * Enables a ConfigTest object. + * + * @param Drupal\config_test\ConfigTest $config_test + * The ConfigTest object to enable. + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse. + */ + function enable(ConfigTest $config_test) { + $config_test->enable()->save(); + return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE))); + } + + /** + * Disables a ConfigTest object. + * + * @param Drupal\config_test\ConfigTest $config_test + * The ConfigTest object to disable. + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse. + */ + function disable(ConfigTest $config_test) { + $config_test->disable()->save(); + return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE))); + } + +} diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/DeleteForm.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/DeleteForm.php new file mode 100644 index 0000000..e69824a --- /dev/null +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/DeleteForm.php @@ -0,0 +1,68 @@ + $this->configTest->label())); + } + + /** + * {@inheritdoc} + */ + protected function getConfirmText() { + return t('Delete'); + } + + + /** + * {@inheritdoc} + */ + protected function getCancelPath() { + return 'admin/structure/config_test'; + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'config_test_delete_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, ConfigTest $config_test = NULL) { + $this->configTest = $config_test; + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $this->configTest->delete(); + drupal_set_message(format_string('%label configuration has been deleted.', array('%label' => $this->configTest->label()))); + $form_state['redirect'] = 'admin/structure/config_test'; + } + +}