Last active
May 23, 2016 18:29
-
-
Save bdombro/6e61cea3a80d058678ff to your computer and use it in GitHub Desktop.
Drupal_Text_to_Textarea.drush.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change a field from textfield to textarea | |
* Unlike other guides online, this one actually corrects the blob values | |
* Run this using drush: `drush scr <filepath>` | |
*/ | |
$field_name = "field_test_text_field_2"; | |
// Update field_config | |
$row = db_query("SELECT id,data FROM {field_config} WHERE field_name = '{$field_name}' ")->fetchObject(); | |
$row->data=unserialize($row->data); | |
unset($row->data['settings']['max_length']); | |
$row->type="text_long"; | |
drupal_write_record("field_config", $row, "id"); | |
// Update field_config_instance | |
$row = db_query("SELECT id,data FROM {field_config_instance} WHERE field_name = '{$field_name}' ")->fetchObject(); | |
$row->data=unserialize($row->data); | |
$row->data['widget']['type']='text_textarea'; | |
unset($row->data['widget']['settings']['size']); | |
$row->data['widget']['settings']['rows']=3; | |
drupal_write_record("field_config_instance", $row, "id"); | |
// Update the field table | |
db_change_field("field_data_{$field_name}", "{$field_name}_value", "{$field_name}_value", array( | |
"type" => "varchar", | |
"length" => "20000", | |
)); | |
db_change_field("field_revision_{$field_name}", "{$field_name}_value", "{$field_name}_value", array( | |
"type" => "varchar", | |
"length" => "20000", | |
)); | |
// Clear caches. | |
field_cache_clear(TRUE); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment