Commit 477cb6ee authored by alexpott's avatar alexpott

Issue #2041225 by swentel: Fixed FieldInstance::delete() doesn't clean up all form modes.

parent 29dd37a2
......@@ -257,19 +257,32 @@ public function testDeleteFieldInstance() {
));
$instance->save();
// Create an entity display.
// Create default and teaser entity display.
entity_create('entity_display', array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'viewMode' => 'default',
'mode' => 'default',
))->setComponent($field_name)->save();
entity_create('entity_display', array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'teaser',
))->setComponent($field_name)->save();
// Check the component exists.
$display = entity_get_display('entity_test', 'entity_test', 'default');
$this->assertTrue($display->getComponent($field_name));
$display = entity_get_display('entity_test', 'entity_test', 'teaser');
$this->assertTrue($display->getComponent($field_name));
// Delete the instance.
$instance->delete();
// Check that the component has been removed from the entity display.
// Check that the component has been removed from the entity displays.
$display = entity_get_display('entity_test', 'entity_test', 'default');
$this->assertFalse($display->getComponent($field_name));
$display = entity_get_display('entity_test', 'entity_test', 'teaser');
$this->assertFalse($display->getComponent($field_name));
}
}
......@@ -120,4 +120,53 @@ public function testFieldComponent() {
$this->assertEqual($widget->getPluginId(), $default_widget);
}
/**
* Tests deleting field instance.
*/
public function testDeleteFieldInstance() {
$this->enableModules(array('field_sql_storage', 'field_test'));
$field_name = 'test_field';
// Create a field and an instance.
$field = entity_create('field_entity', array(
'name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'test_field'
));
$field->save();
$instance = entity_create('field_instance', array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
));
$instance->save();
// Create default and compact entity display.
entity_create('entity_form_display', array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
))->setComponent($field_name)->save();
entity_create('entity_form_display', array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'compact',
))->setComponent($field_name)->save();
// Check the component exists.
$display = entity_get_form_display('entity_test', 'entity_test', 'default');
$this->assertTrue($display->getComponent($field_name));
$display = entity_get_form_display('entity_test', 'entity_test', 'compact');
$this->assertTrue($display->getComponent($field_name));
// Delete the instance.
$instance->delete();
// Check that the component has been removed from the entity displays.
$display = entity_get_form_display('entity_test', 'entity_test', 'default');
$this->assertFalse($display->getComponent($field_name));
$display = entity_get_form_display('entity_test', 'entity_test', 'compact');
$this->assertFalse($display->getComponent($field_name));
}
}
......@@ -458,7 +458,12 @@ public function delete($field_cleanup = TRUE) {
field_cache_clear();
// Remove the instance from the entity form displays.
if ($form_display = entity_load('entity_form_display', $this->entity_type . '.' . $this->bundle . '.default')) {
$ids = array();
$form_modes = array('default' => array()) + entity_get_form_modes($this->entity_type);
foreach (array_keys($form_modes) as $form_mode) {
$ids[] = $this->entity_type . '.' . $this->bundle . '.' . $form_mode;
}
foreach (entity_load_multiple('entity_form_display', $ids) as $form_display) {
$form_display->removeComponent($this->field->name)->save();
}
......
......@@ -158,6 +158,23 @@ function entity_test_entity_view_mode_info_alter(&$view_modes) {
}
}
/**
* Implements hook_entity_form_mode_info_alter().
*/
function entity_test_entity_form_mode_info_alter(&$form_modes) {
$entity_info = entity_get_info();
foreach ($entity_info as $entity_type => $info) {
if ($entity_info[$entity_type]['module'] == 'entity_test') {
$form_modes[$entity_type] = array(
'compact' => array(
'label' => t('Compact version'),
'status' => TRUE,
),
);
}
}
}
/**
* Implements hook_field_extra_fields().
*/
......
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