Issue #1211008 by yched, tim.plunkett, DamienMcKenna: Split field_bundle_settings() out per bundle.

merge-requests/26/head
webchick 2012-04-12 00:50:52 -07:00
parent 84194b38e3
commit e22feb7123
6 changed files with 108 additions and 17 deletions

View File

@ -1321,12 +1321,9 @@ function field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
field_cache_clear();
// Update bundle settings.
$settings = variable_get('field_bundle_settings', array());
if (isset($settings[$entity_type][$bundle_old])) {
$settings[$entity_type][$bundle_new] = $settings[$entity_type][$bundle_old];
unset($settings[$entity_type][$bundle_old]);
variable_set('field_bundle_settings', $settings);
}
$settings = variable_get('field_bundle_settings_' . $entity_type . '__' . $bundle_old, array());
variable_set('field_bundle_settings_' . $entity_type . '__' . $bundle_new, $settings);
variable_del('field_bundle_settings_' . $entity_type . '__' . $bundle_old);
// Let other modules act on renaming the bundle.
module_invoke_all('field_attach_rename_bundle', $entity_type, $bundle_old, $bundle_new);
@ -1360,11 +1357,7 @@ function field_attach_delete_bundle($entity_type, $bundle) {
field_cache_clear();
// Clear bundle display settings.
$settings = variable_get('field_bundle_settings', array());
if (isset($settings[$entity_type][$bundle])) {
unset($settings[$entity_type][$bundle]);
variable_set('field_bundle_settings', $settings);
}
variable_del('field_bundle_settings_' . $entity_type . '__' . $bundle);
// Let other modules act on deleting the bundle.
module_invoke_all('field_attach_delete_bundle', $entity_type, $bundle, $instances);

View File

@ -436,3 +436,27 @@ function field_update_7001() {
/**
* @} End of "addtogroup updates-6.x-to-7.x"
*/
/**
* @addtogroup updates-7.x-extra
* @{
*/
/**
* Split the all-inclusive field_bundle_settings variable per bundle.
*/
function field_update_7002() {
$settings = variable_get('field_bundle_settings', array());
if ($settings) {
foreach ($settings as $entity_type => $entity_type_settings) {
foreach ($entity_type_settings as $bundle => $bundle_settings) {
variable_set('field_bundle_settings_' . $entity_type . '__' . $bundle, $bundle_settings);
}
}
variable_del('field_bundle_settings');
}
}
/**
* @} End of "addtogroup updates-7.x-extra"
*/

View File

@ -603,16 +603,12 @@ function _field_sort_items_value_helper($a, $b) {
* If no $settings are passed, the current settings are returned.
*/
function field_bundle_settings($entity_type, $bundle, $settings = NULL) {
$stored_settings = variable_get('field_bundle_settings', array());
if (isset($settings)) {
$stored_settings[$entity_type][$bundle] = $settings;
variable_set('field_bundle_settings', $stored_settings);
variable_set('field_bundle_settings_' . $entity_type . '__' . $bundle, $settings);
field_info_cache_clear();
}
else {
$settings = isset($stored_settings[$entity_type][$bundle]) ? $stored_settings[$entity_type][$bundle] : array();
$settings = variable_get('field_bundle_settings_' . $entity_type . '__' . $bundle, array());
$settings += array(
'view_modes' => array(),
'extra_fields' => array(),

View File

@ -40,6 +40,7 @@ files[] = tests/update.test
files[] = tests/xmlrpc.test
files[] = tests/upgrade/upgrade.test
files[] = tests/upgrade/upgrade.comment.test
files[] = tests/upgrade/update.field.test
files[] = tests/upgrade/upgrade.filter.test
files[] = tests/upgrade/upgrade.forum.test
files[] = tests/upgrade/upgrade.locale.test

View File

@ -0,0 +1,16 @@
<?php
/**
* @file
* Test content for the field update path.
*/
db_insert('variable')->fields(array(
'name',
'value',
))
->values(array(
'name' => 'field_bundle_settings',
'value' => 'a:1:{s:4:"node";a:1:{s:4:"poll";a:1:{s:12:"extra_fields";a:1:{s:7:"display";a:2:{s:16:"poll_view_voting";a:1:{s:7:"default";a:2:{s:6:"weight";s:1:"0";s:7:"visible";b:1;}}s:17:"poll_view_results";a:1:{s:7:"default";a:2:{s:6:"weight";s:1:"0";s:7:"visible";b:0;}}}}}}}',
))
->execute();

View File

@ -0,0 +1,61 @@
<?php
/**
* @file
* Provides update path tests for the Field module.
*/
/**
* Tests the Field 7.0 -> 7.x update path.
*/
class FieldUpdatePathTestCase extends UpdatePathTestCase {
public static function getInfo() {
return array(
'name' => 'Field update path',
'description' => 'Field update path tests.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Use the filled update path and our field data.
$path = drupal_get_path('module', 'simpletest') . '/tests/upgrade';
$this->databaseDumpFiles = array(
$path . '/drupal-7.filled.standard_all.database.php.gz',
$path . '/drupal-7.field.database.php',
);
parent::setUp();
// Our test data includes poll extra field settings.
$this->uninstallModulesExcept(array('field', 'poll'));
}
/**
* Tests that the update is successful.
*/
public function testFilledUpgrade() {
$this->assertTrue($this->performUpgrade(), t('The update was completed successfully.'));
$expected_settings = array(
'extra_fields' => array(
'display' => array(
'poll_view_voting' => array(
'default' => array(
'weight' => '0',
'visible' => TRUE,
),
),
'poll_view_results' => array(
'default' => array(
'weight' => '0',
'visible' => FALSE,
),
),
),
'form' => array(),
),
'view_modes' => array(),
);
$actual_settings = field_bundle_settings('node', 'poll');
$this->assertEqual($expected_settings, $actual_settings, 'Settings stored in field_bundle_settings were updated to per-bundle settings.');
}
}