diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index c2c004c..d144ac0 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -32,15 +32,11 @@ 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, + 'route_name' => 'config_test_entity_edit', ); $items['admin/structure/config_test/manage/%config_test/edit'] = array( 'title' => 'Edit', @@ -48,22 +44,15 @@ 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, - '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 +68,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 +85,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..61221c6 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,50 @@ 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: + pattern: 'admin/structure/config_test/manage/{config_test}' + defaults: + _controller: '\Drupal\config_test\ConfigTestController::edit' + entity_type: '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\ConfigTestDeleteForm' + 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..b7b6458 --- /dev/null +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestController.php @@ -0,0 +1,62 @@ + $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 + * A redirect response to the config_test listing page. + */ + 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 + * A redirect response to the config_test listing page. + */ + 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/ConfigTestInterface.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestInterface.php new file mode 100644 index 0000000..2752b9c --- /dev/null +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestInterface.php @@ -0,0 +1,17 @@ + $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'; + } + + /** + * Implements \Drupal\Drupal\Core\Form\ConfirmFormBase::buildForm(). + * + * @param \Drupal\config_test\ConfigTestInterface $config_test + * (optional) The ConfigTestInterface object to delete. + */ + public function buildForm(array $form, array &$form_state, ConfigTestInterface $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(String::format('%label configuration has been deleted.', array('%label' => $this->configTest->label()))); + $form_state['redirect'] = 'admin/structure/config_test'; + } + +} 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..4136d42 --- /dev/null +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/DeleteForm.php @@ -0,0 +1,75 @@ + $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'; + } + + /** + * Implements \Drupal\Drupal\Core\Form\ConfirmFormBase::buildForm(). + * + * @param \Drupal\config_test\ConfigTestInterface $config_test + * (optional) The ConfigTestInterface object to delete. + */ + public function buildForm(array $form, array &$form_state, ConfigTestInterface $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(String::format('%label configuration has been deleted.', array('%label' => $this->configTest->label()))); + $form_state['redirect'] = 'admin/structure/config_test'; + } + +} diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php index 2983a44..0344334 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; +use Drupal\config_test\ConfigTestInterface; /** * Defines the ConfigTest configuration entity. @@ -35,7 +36,7 @@ * } * ) */ -class ConfigTest extends ConfigEntityBase { +class ConfigTest extends ConfigEntityBase implements ConfigTestInterface { /** * The machine name for the configuration entity.