diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php index b659ace..5f8b709 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php @@ -90,14 +90,6 @@ function testDeleted() { $config = config($dynamic_name); $this->assertIdentical($config->get('id'), NULL); - // Verify that appropriate module API hooks have been invoked. - $this->assertTrue(isset($GLOBALS['hook_config_test']['load'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['presave'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['insert'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['update'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['predelete'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['delete'])); - // Verify that there is nothing more to import. $this->assertFalse(config_sync_get_changes($staging, $storage)); } @@ -146,14 +138,6 @@ function testNew() { $config = config($dynamic_name); $this->assertIdentical($config->get('label'), $original_dynamic_data['label']); - // Verify that appropriate module API hooks have been invoked. - $this->assertFalse(isset($GLOBALS['hook_config_test']['load'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['presave'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['insert'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['update'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['predelete'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['delete'])); - // Verify that there is nothing more to import. $this->assertFalse(config_sync_get_changes($staging, $storage)); } @@ -206,14 +190,6 @@ function testUpdated() { $this->assertIdentical($staging->read($name), $original_name_data); $this->assertIdentical($staging->read($dynamic_name), $original_dynamic_data); - // Verify that appropriate module API hooks have been invoked. - $this->assertTrue(isset($GLOBALS['hook_config_test']['load'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['presave'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['insert'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['update'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['predelete'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['delete'])); - // Verify that there is nothing more to import. $this->assertFalse(config_sync_get_changes($staging, $storage)); } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php index 3e6a88e..3a36779 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php @@ -47,13 +47,5 @@ function testModuleInstallation() { // configuration entity. $this->assertTrue($GLOBALS['hook_config_import']); - // Verify that config_test API hooks were invoked for the dynamic default - // configuration entity. - $this->assertFalse(isset($GLOBALS['hook_config_test']['load'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['presave'])); - $this->assertTrue(isset($GLOBALS['hook_config_test']['insert'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['update'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['predelete'])); - $this->assertFalse(isset($GLOBALS['hook_config_test']['delete'])); } } diff --git a/core/modules/config/tests/config_test/config_test.hooks.inc b/core/modules/config/tests/config_test/config_test.hooks.inc deleted file mode 100644 index 80f3381..0000000 --- a/core/modules/config/tests/config_test/config_test.hooks.inc +++ /dev/null @@ -1,52 +0,0 @@ - 'Drupal\Core\Config\Entity\ConfigStorageController', 'entity class' => 'Drupal\config_test\ConfigTest', 'list controller class' => 'Drupal\Core\Config\Entity\ConfigEntityListController', + 'form controller class' => array( + 'default' => 'Drupal\config_test\ConfigTestFormController', + ), 'uri callback' => 'config_test_uri', 'config prefix' => 'config_test.dynamic', 'entity keys' => array( @@ -117,15 +100,14 @@ function config_test_menu() { ); $items['admin/structure/config_test/add'] = array( 'title' => 'Add test configuration', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('config_test_form'), + 'page callback' => 'config_test_add', 'access callback' => TRUE, 'type' => MENU_LOCAL_ACTION, ); $items['admin/structure/config_test/manage/%config_test'] = array( 'title' => 'Edit test configuration', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('config_test_form', 4), + 'page callback' => 'entity_get_form', + 'page arguments' => array(4), 'access callback' => TRUE, ); $items['admin/structure/config_test/manage/%config_test/edit'] = array( @@ -154,26 +136,6 @@ function config_test_load($id) { } /** - * Saves a ConfigTest object. - * - * @param Drupal\config_test\ConfigTest $config_test - * The ConfigTest object to save. - */ -function config_test_save(ConfigTest $config_test) { - return $config_test->save(); -} - -/** - * Deletes a ConfigTest object. - * - * @param string $id - * The ID of the ConfigTest object to delete. - */ -function config_test_delete($id) { - entity_delete_multiple('config_test', array($id)); -} - -/** * Page callback; Lists available ConfigTest objects. */ function config_test_list_page() { @@ -182,79 +144,11 @@ function config_test_list_page() { } /** - * Form constructor to add or edit a ConfigTest object. - * - * @param Drupal\config_test\ConfigTest $config_test - * (optional) An existing ConfigTest object to edit. If omitted, the form - * creates a new ConfigTest. + * Menu callback: displays the 'Add new config_test' form. */ -function config_test_form($form, &$form_state, ConfigTest $config_test = NULL) { - // Standard procedure for handling the entity argument in entity forms, taking - // potential form caching and rebuilds properly into account. - // @see http://drupal.org/node/1499596 - if (!isset($form_state['config_test'])) { - if (!isset($config_test)) { - $config_test = entity_create('config_test', array()); - } - $form_state['config_test'] = $config_test; - } - else { - $config_test = $form_state['config_test']; - } - - $form['label'] = array( - '#type' => 'textfield', - '#title' => 'Label', - '#default_value' => $config_test->label(), - '#required' => TRUE, - ); - $form['id'] = array( - '#type' => 'machine_name', - '#default_value' => $config_test->id(), - '#required' => TRUE, - '#machine_name' => array( - 'exists' => 'config_test_load', - // @todo Update form_process_machine_name() to use 'label' by default. - 'source' => array('label'), - ), - ); - $form['style'] = array( - '#type' => 'select', - '#title' => 'Image style', - '#options' => array(), - '#default_value' => $config_test->get('style'), - '#access' => FALSE, - ); - if (module_exists('image')) { - $form['style']['#access'] = TRUE; - $form['style']['#options'] = image_style_options(); - } - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Save'); - - return $form; -} - -/** - * Form submission handler for config_test_form(). - */ -function config_test_form_submit($form, &$form_state) { - form_state_values_clean($form_state); - - $config_test = $form_state['config_test']; - entity_form_submit_build_entity('config_test', $config_test, $form, $form_state); - - $status = $config_test->save(); - - if ($status == SAVED_UPDATED) { - drupal_set_message(format_string('%label configuration has been updated.', array('%label' => $config_test->label()))); - } - else { - drupal_set_message(format_string('%label configuration has been created.', array('%label' => $config_test->label()))); - } - - $form_state['redirect'] = 'admin/structure/config_test'; +function config_test_add() { + $entity = entity_create('config_test', array()); + return entity_get_form($entity); } /** diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestFormController.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestFormController.php new file mode 100644 index 0000000..3381702 --- /dev/null +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/ConfigTestFormController.php @@ -0,0 +1,106 @@ +getFormLangcode($form_state); + $name = $entity->get('name', $langcode); + $uid = $entity->get('uid', $langcode); + + $form['label'] = array( + '#type' => 'textfield', + '#title' => 'Label', + '#default_value' => $entity->label(), + '#required' => TRUE, + ); + $form['id'] = array( + '#type' => 'machine_name', + '#default_value' => $entity->id(), + '#required' => TRUE, + '#machine_name' => array( + 'exists' => 'config_test_load', + // @todo Update form_process_machine_name() to use 'label' by default. + 'source' => array('label'), + ), + ); + $form['style'] = array( + '#type' => 'select', + '#title' => 'Image style', + '#options' => array(), + '#default_value' => $entity->get('style'), + '#access' => FALSE, + ); + if (module_exists('image')) { + $form['style']['#access'] = TRUE; + $form['style']['#options'] = image_style_options(); + } + + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Save'); + + return $form; + } + + /** + * Overrides Drupal\Core\Entity\EntityFormController::submit(). + */ + public function submit(array $form, array &$form_state) { + form_state_values_clean($form_state); + $entity = parent::submit($form, $form_state); + + return $entity; + } + + /** + * Overrides Drupal\Core\Entity\EntityFormController::save(). + */ + public function save(array $form, array &$form_state) { + $entity = $this->getEntity($form_state); + $status = $entity->save(); + + if ($status == SAVED_UPDATED) { + drupal_set_message(t('%label configuration has been updated.', array('%label' => $entity->label()))); + } + else { + drupal_set_message(t('%label configuration has been created.', array('%label' => $entity->label()))); + } + + if ($entity->id()) { + $form_state['redirect'] = 'admin/structure/config_test/manage'; + } + else { + // Error on save. + drupal_set_message(t('The entity could not be saved.'), 'error'); + $form_state['rebuild'] = TRUE; + } + } + + /** + * Overrides Drupal\Core\Entity\EntityFormController::delete(). + */ + public function delete(array $form, array &$form_state) { + $entity = $this->getEntity($form_state); + $entity->delete(); + drupal_set_message(t('config_test @label has been deleted.', array('@label' => $entity->label()))); + $form_state['redirect'] = 'admin/structure/config_test/manage'; + } + +}