Getting all the text field sizes!

15 Nov 2012

Posted by admin

I was not able to find a quick way to figure out what the field size (in the content dialog known as "Size of textfield") so I wrote up a little drush script to tell me what they all are.

<?php
/**
* Get the sizes of all text fields. Drush script, run with "drush php-script filename"
*/
$result = db_query('select field_name,data from field_config_instance;');
foreach (
$result as $record) {
 
// The size of a text field is hidden away in this serialized data blob.
 
$data = unserialize($record->data);
  if (isset(
$data['widget']['settings']['size'])) {
    print
$record->field_name . ": ";
    print
'Size: ' . $data['widget']['settings']['size'] . PHP_EOL;
  }
}
?>

As it says in the description, this is a script you run from your terminal, and only if you have drush installed. To use it, cd to your site directory, spackle the above code into a file in the root of the site, call it something like get_all_the_sizes.php, and then run it with the following command:

drush php-script get_all_the_sizes

It will then output some niftyness into your shell that looks like this:

field_global_authorizer: Size: 60
field_global_school: Size: 60
field_authorizer_renewal_time: Size: 60
field_authorizer_review_period: Size: 60
field_authorizer_type: Size: 60
field_global_operator: Size: 60
field_school_additional_info: Size: 60
field_school_grades: Size: 60
field_source_value: Size: 60
field_school_nces_id: Size: 60
field_authorizer_charter_length: Size: 60
field_authorizer_charter_length2: Size: 60
field_school_status: Size: 60

Yay!

Sitewide Terms: