Index: filefield.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.module,v retrieving revision 1.189 diff -u -r1.189 filefield.module --- filefield.module 12 Apr 2009 02:04:28 -0000 1.189 +++ filefield.module 12 Apr 2009 19:10:43 -0000 @@ -205,6 +205,16 @@ } /** + * Implementation of hook_views_api(). + */ +function filefield_views_api() { + return array( + 'api' => 2.0, + 'path' => drupal_get_path('module', 'filefield') . '/views', + ); +} + +/** * Implementation of hook_form_alter(). * * Set the enctype on forms that need to accept file uploads. Index: filefield_field.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_field.inc,v retrieving revision 1.28 diff -u -r1.28 filefield_field.inc --- filefield_field.inc 1 Apr 2009 19:58:07 -0000 1.28 +++ filefield_field.inc 12 Apr 2009 19:10:43 -0000 @@ -50,9 +50,9 @@ */ function filefield_field_settings_database_columns($field) { return array( - 'fid' => array('type' => 'int', 'not null' => FALSE), - 'list' => array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE), - 'data' => array('type' => 'text', 'serialize' => TRUE), + 'fid' => array('type' => 'int', 'not null' => FALSE, 'views' => TRUE), + 'list' => array('type' => 'int', 'size' => 'tiny', 'not null' => FALSE, 'views' => TRUE), + 'data' => array('type' => 'text', 'serialize' => TRUE, 'views' => TRUE), ); } @@ -64,9 +64,6 @@ $db_info = content_database_info($field); $table_alias = content_views_tablename($field); - // Set our own field handler so that we can hook the file formatter - // configuration table into the options form. - // By defining the relationship, we already have a "Has file" filter // plus all the filters that Views already provides for files. // No need for having a filter by ourselves. @@ -80,6 +77,27 @@ 'label' => t($field['widget']['label']), 'content_field_name' => $field['field_name'], ); + + // Use the Views boolean handler for filtering the list value. + $data[$table_alias][$field['field_name'] .'_list']['filter']['handler'] = 'views_handler_filter_boolean_operator'; + + // Add our special handler for serialized data. + $data[$table_alias][$field['field_name'] .'_data']['field'] = array( + 'title' => $data[$table_alias][$field['field_name'] .'_data']['title'], + 'title short' => $data[$table_alias][$field['field_name'] .'_data']['title short'], + 'field' => $db_info['columns']['data']['column'], + 'table' => $db_info['table'], + 'handler' => 'filefield_handler_field_data', + 'click sortable' => FALSE, + 'access callback' => 'content_access', + 'access arguments' => array('view', $field), + ); + + // Remove handlers that are probably unnecessary. + unset($data[$table_alias][$field['field_name'] .'_data']['filter']); + unset($data[$table_alias][$field['field_name'] .'_data']['argument']); + unset($data[$table_alias][$field['field_name'] .'_list']['argument']); + return $data; } Index: views/filefield.views.inc =================================================================== RCS file: views/filefield.views.inc diff -N views/filefield.views.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views/filefield.views.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,34 @@ + array( + 'path' => drupal_get_path('module', 'filefield') . '/views', + ), + 'handlers' => array( + // field handlers + 'filefield_handler_field_data' => array( + 'parent' => 'views_handler_field_node', + ), + ), + ); +} + +/** + * @} + */ Index: views/filefield_handler_field_data.inc =================================================================== RCS file: views/filefield_handler_field_data.inc diff -N views/filefield_handler_field_data.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ views/filefield_handler_field_data.inc 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,44 @@ + t('Data key'), + '#type' => 'radios', + // TODO: Pull these values from the modules that extend FileField. + '#options' => drupal_map_assoc(array('description', 'title', 'alt')), + '#required' => TRUE, + '#default_value' => $this->options['data_key'], + '#description' => t('The data column may (or may not) contain any of the following data. Select the data that should be output for this field.'), + '#weight' => 4, + ); + } + + function admin_summary() { + // Display the data to be displayed + return $this->options['data_key']; + } + + function render($values) { + $values = drupal_clone($values); // Prevent affecting the original. + $data = unserialize($values->{$this->field_alias}); + $values->{$this->field_alias} = $data[$this->options['data_key']]; + return parent::render($values); + } + +}