Commit 1184ed9f authored by Dries's avatar Dries

- Patch#583020 by c960657 | yched, Dries: fixed warning about missing argument...

- Patch#583020 by c960657 | yched, Dries: fixed warning about missing argument 2 for field_delete_instance() in node_configure_fields().
parent 04fd066b
......@@ -1328,7 +1328,7 @@ function field_attach_delete_bundle($bundle) {
// First, delete the instances themseves.
$instances = field_info_instances($bundle);
foreach ($instances as $instance) {
field_delete_instance($instance['field_name'], $bundle);
field_delete_instance($instance);
}
// Clear the cache.
......
......@@ -541,7 +541,8 @@ function field_delete_field($field_name) {
$field = field_info_field($field_name);
if (isset($field['bundles'])) {
foreach ($field['bundles'] as $bundle) {
field_delete_instance($field_name, $bundle);
$instance = field_info_instance($field_name, $bundle);
field_delete_instance($instance);
}
}
......@@ -832,24 +833,19 @@ function field_read_instances($params = array(), $include_additional = array())
* Mark a field instance for deletion, including all data associated with
* it.
*
* @param $field_name
* The name of the field whose instance will be deleted.
* @param $bundle
* The bundle for the instance which will be deleted.
* @param $instance
* An instance structure.
*/
function field_delete_instance($field_name, $bundle) {
// Save the instance for hook_field_delete_instance before it is deleted.
$instance = field_info_instance($field_name, $bundle);
function field_delete_instance($instance) {
// Mark the field instance for deletion.
db_update('field_config_instance')
->fields(array('deleted' => 1))
->condition('field_name', $field_name)
->condition('bundle', $bundle)
->condition('field_name', $instance['field_name'])
->condition('bundle', $instance['bundle'])
->execute();
// Mark instance data for deletion.
$field = field_info_field($field_name);
$field = field_info_field($instance['field_name']);
module_invoke($field['storage']['module'], 'field_storage_delete_instance', $instance);
// Clear the cache.
......
......@@ -2125,12 +2125,12 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
field_create_instance($this->instance_definition);
$this->another_instance_definition = $this->instance_definition;
$this->another_instance_definition['bundle'] .= '_another_bundle';
field_create_instance($this->another_instance_definition);
$instance = field_create_instance($this->another_instance_definition);
// Test that the first instance is not deleted, and then delete it.
$instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$this->assertTrue(!empty($instance) && empty($instance['deleted']), t('A new field instance is not marked for deletion.'));
field_delete_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
field_delete_instance($instance);
// Make sure the instance is marked as deleted when the instance is
// specifically loaded.
......@@ -2490,7 +2490,8 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
$this->assertEqual(count($found['test_entity']), 10, 'Correct number of objects found before deleting');
// Delete the instance.
field_delete_instance($field['field_name'], $bundle);
$instance = field_info_instance($field['field_name'], $bundle);
field_delete_instance($instance);
// The instance still exists, deleted.
$instances = field_read_instances(array('field_id' => $field['id'], 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1));
......@@ -2522,7 +2523,8 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
$field = reset($this->fields);
// Delete the instance.
field_delete_instance($field['field_name'], $bundle);
$instance = field_info_instance($field['field_name'], $bundle);
field_delete_instance($instance);
// No field hooks were called.
$mem = field_test_memorize();
......@@ -2577,7 +2579,8 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
foreach ($this->bundles as $bundle) {
// Delete the instance.
field_delete_instance($field['field_name'], $bundle);
$instance = field_info_instance($field['field_name'], $bundle);
field_delete_instance($instance);
// Purge the data.
field_purge_batch(10);
......
......@@ -979,7 +979,7 @@ function field_ui_field_delete_form_submit($form, &$form_state) {
$bundle_label = $bundles[$bundle]['label'];
if (!empty($bundle) && $field && !$field['locked'] && $form_values['confirm']) {
field_delete_instance($field['field_name'], $bundle);
field_delete_instance($instance);
// Delete the field if that was the last instance.
if (count($field['bundles'] == 1)) {
field_delete_field($field['field_name']);
......
......@@ -857,6 +857,56 @@ class NodeTypeTestCase extends DrupalWebTestCase {
$this->drupalGet('node/add/' . str_replace('_', '-', $type->name));
$this->assertResponse(200, 'The new content type can be accessed at node/add.');
}
/**
* Test editing a node type using the UI.
*/
function testNodeTypeEditing() {
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types'));
$this->drupalLogin($web_user);
$instance = field_info_instance('body', 'page');
$this->assertEqual($instance['label'], 'Body', t('Body field was found.'));
// Verify that title and body fields are displayed.
$this->drupalGet('node/add/page');
$this->assertRaw('Title', t('Title field was found.'));
$this->assertRaw('Full text', t('Body field was found.'));
// Rename the title field and remove the body field.
$edit = array(
'title_label' => 'Foo',
'body_label' => '',
);
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
field_info_cache_clear();
$this->assertFalse(field_info_instance('body', 'page'), t('Body field was removed.'));
$this->drupalGet('node/add/page');
$this->assertRaw('Foo', t('New title label was displayed.'));
$this->assertNoRaw('Title', t('Old title label was not displayed.'));
$this->assertNoRaw('Full text', t('Body field was not found.'));
// Add the body field again and change the name, machine name and description.
$edit = array(
'name' => 'Bar',
'type' => 'bar',
'description' => 'Lorem ipsum.',
'body_label' => 'Baz',
);
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
field_info_cache_clear();
$instance = field_info_instance('body', 'bar');
$this->assertEqual($instance['label'], 'Baz', t('Body field was added.'));
$this->drupalGet('node/add');
$this->assertRaw('Bar', t('New name was displayed.'));
$this->assertRaw('Lorem ipsum', t('New description was displayed.'));
$this->clickLink('Bar');
$this->assertEqual(url('node/add/bar', array('absolute' => TRUE)), $this->getUrl(), t('New machine name was used in URL.'));
$this->assertRaw('Foo', t('Title field was found.'));
$this->assertRaw('Full text', t('Body field was found.'));
}
}
/**
......
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