Index: filefield.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.module,v retrieving revision 1.229 diff -u -r1.229 filefield.module --- filefield.module 6 Dec 2010 06:53:06 -0000 1.229 +++ filefield.module 8 Dec 2010 04:44:48 -0000 @@ -473,6 +473,59 @@ } /** + * Get a list of possible information stored in a file field "data" column. + */ +function filefield_data_info() { + static $columns; + + if (!isset($columns)) { + $columns = array(); + foreach (module_implements('filefield_data_info') as $module) { + $function = $module . '_filefield_data_info'; + $data = (array) $function(); + foreach ($data as $key => $value) { + $data[$key] = $value; + $data[$key]['module'] = $module; + } + $columns = array_merge($columns, $data); + } + } + + return $columns; +} + +/** + * Given an array of data options, dispatch the necessary callback function. + */ +function filefield_data_value($key, $value) { + $info = filefield_data_info(); + if (isset($info[$key]['callback'])) { + $callback = $info[$key]['callback']; + $value = $callback($value); + } + else { + $value = check_plain((string) $value); + } + return $value; +} + +/** + * Implementation of hook_filefield_data_info(). + * + * Define a list of values that this module stores in the "data" column of a + * file field. The callback function receives the portion of the data column + * defined by key and should return a value suitable for printing to the page. + */ +function filefield_filefield_data_info() { + return array( + 'description' => array( + 'title' => t('Description'), + 'callback' => 'check_plain', + ), + ); +} + +/** * Determine the most appropriate icon for the given file's mimetype. * * @param $file @@ -485,7 +538,6 @@ return _filefield_icon_url($file); } - /** * Implementation of hook_filefield_icon_sets(). * Index: views/filefield_handler_field_data.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/views/filefield_handler_field_data.inc,v retrieving revision 1.2 diff -u -r1.2 filefield_handler_field_data.inc --- views/filefield_handler_field_data.inc 8 Jan 2010 22:38:40 -0000 1.2 +++ views/filefield_handler_field_data.inc 8 Dec 2010 04:44:48 -0000 @@ -18,27 +18,33 @@ function options_form(&$form, &$form_state) { parent::options_form($form, $form_state); + $options = array(); + $info = filefield_data_info(); + foreach ($info as $key => $data) { + $options[$key] = $data['title'] . ' (' . $data['module'] .')'; + } + $form['data_key'] = array( '#title' => t('Data key'), '#type' => 'radios', - // TODO: Pull these values from the modules that extend FileField. - '#options' => drupal_map_assoc(array('description', 'title', 'alt')), + '#options' => $options, '#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.'), + '#description' => t('The data column may contain only a few or none any of these data options. The name of the module that provides the data is shown in parathesis.'), '#weight' => 4, ); } function admin_summary() { - // Display the data to be displayed - return $this->options['data_key']; + // Display the data to be displayed. + $info = filefield_data_info(); + return isset($info[$this->options['data_key']]['title']) ? $info[$this->options['data_key']]['title'] : $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']]; + $values->{$this->field_alias} = filefield_data_value($this->options['data_key'], $data[$this->options['data_key']]); return parent::render($values); }