summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Haug2010-12-08 04:57:07 +0000
committerNathan Haug2010-12-08 04:57:07 +0000
commit0aee4560d20e5d74cc2d534cb02a6cc727b99563 (patch)
tree2a48ac0355b9c8694212c38b5cdd94bad66df0cc
parent1b407395918eb73e6409f09d89d1e226a0a6769b (diff)
#735512: Adding hook to allow other modules to utilize the "data" column in a supported fashion.
-rw-r--r--filefield.module54
-rw-r--r--views/filefield_handler_field_data.inc18
2 files changed, 65 insertions, 7 deletions
diff --git a/filefield.module b/filefield.module
index d90fa71..9fff10f 100644
--- a/filefield.module
+++ b/filefield.module
@@ -473,6 +473,59 @@ function filefield_content_generate($node, $field) {
}
/**
+ * 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 @@ function filefield_icon_url($file) {
return _filefield_icon_url($file);
}
-
/**
* Implementation of hook_filefield_icon_sets().
*
diff --git a/views/filefield_handler_field_data.inc b/views/filefield_handler_field_data.inc
index 9b8c711..736532e 100644
--- a/views/filefield_handler_field_data.inc
+++ b/views/filefield_handler_field_data.inc
@@ -18,27 +18,33 @@ class filefield_handler_field_data extends views_handler_field_node {
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);
}