public function Field::rename in Little helpers 7.2
Same name and namespace in other branches
- 7 src/Field/Field.php \Drupal\little_helpers\Field\Field::rename()
Change the machine name of an existing field.
Parameters
$newName string:
NOTE: This might need additional adjustments for contrib modules that store field_names (ie. views, context, cck_blocks).
File
- src/
Field/ Field.php, line 99
Class
- Field
- OOP-wrapper for the data-structure used by field_*_field() functions.
Namespace
Drupal\little_helpers\FieldCode
public function rename($newName) {
$o = $this->field_name;
$n = $newName;
db_query("UPDATE field_config SET field_name='{$n}' WHERE field_name='{$o}'");
db_query("UPDATE field_config_instance SET field_name='{$n}' WHERE field_name='{$o}'");
db_query("RENAME TABLE `field_data_{$o}` TO `field_data_{$n}`;");
db_query("RENAME TABLE `field_revision_{$o}` TO `field_revision_{$n}`;");
\module_load_install($this->module);
$function = $this->module . '_field_schema';
$schema = $function(array(
'type' => $this->type,
));
foreach ($schema['columns'] as $column => $specs) {
db_change_field("field_data_{$n}", "{$o}_{$column}", "{$n}_{$column}", $specs);
db_change_field("field_revision_{$n}", "{$o}_{$column}", "{$n}_{$column}", $specs);
}
$this->field_name = $n;
}