I would like to be able to add a handful of custom attributes to a filefield. The attributes will be used by other modules to manage the uploaded files.

For example: Admin creates a filefield and adds a "youtube" attribute, meaning that videos uploaded to this filefield should get transferred to youtube.

I see that the database table content_node_field (which contains a row for each defined field) has a general_settings column that stores serialized data. I am assuming this is a good place to store my custom field attributes.

Question #1:
How to set/get custom attributes stored under the "general_settings" column?

Question #2: How to customize the filefield widget so that when admin defines a particular filefield, she can also select values for these custom attributes.

(I am using Drupal 6.)

Thank you!

1 Answer 1


The database table "content_node_field_instance" has a "widget_settings" column which can be used to store field attributes. Use hook_widget_settings_alter() to associate attributes with a field. Admin will then be able to set attribute values from the cck UI. For example, to associate a binary attribute "my_attribute" with every filefield:

function mymodule_widget_settings_alter(&$settings, $op, $widget) {

  // Apply to all FileFields 
  $widget_types = _content_widget_types();
  $widget_type = isset($widget['widget_type']) ? $widget['widget_type'] : $widget['type'];
  if (!in_array('filefield', $widget_types[$widget_type]['field types'])) {

  switch ($op) {
      case 'form': 
        $settings['my_attribute'] = array(
          '#type' => 'checkbox',
          '#title' => t('my attribute'),
          '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
          '#default_value' => !empty($widget['my_attribute']),

      case 'save':
        $settings[] = 'my_attribute';

In this example, the filefield form will contain a checkbox labeled "my attribute". Admin checks the box to set my_attribute to true, for the particular filefield.

To get the attribute value of a particular field:

$attribute_value = $field['widget']['my_attribute'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.