summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Haug2011-04-27 16:03:14 -0600
committerNathan Haug2011-04-27 16:03:14 -0600
commitef3337444639924a3642c89d3ac69680265bca51 (patch)
tree5010e157f0ad874e687cbee663d9778e779dbd15
parent6b703b0154fa34f1449515649d76e3ba6685999c (diff)
Issue #600798: Obtain icon on views fields related to a filefield.
-rw-r--r--views/filefield.views.inc24
-rw-r--r--views/filefield_handler_field_icon.inc25
2 files changed, 49 insertions, 0 deletions
diff --git a/views/filefield.views.inc b/views/filefield.views.inc
index 8bc22ff..f35dc11 100644
--- a/views/filefield.views.inc
+++ b/views/filefield.views.inc
@@ -11,6 +11,27 @@
* @{
*/
+
+/**
+ * Implementation of hook_views_data()
+ */
+function filefield_views_data() {
+ $data = array();
+
+ // Extend the files table with an icon field.
+ $data['files']['icon'] = array(
+ 'title' => t('Icon'),
+ 'help' => t('An icon corresponding to the file MIME type.'),
+ 'real field' => 'filemime',
+ 'field' => array(
+ 'handler' => 'filefield_handler_field_icon',
+ 'click sortable' => FALSE,
+ ),
+ );
+
+ return $data;
+}
+
/**
* Implementation of hook_views_handlers().
*/
@@ -24,6 +45,9 @@ function filefield_views_handlers() {
'filefield_handler_field_data' => array(
'parent' => 'views_handler_field_node',
),
+ 'filefield_handler_field_icon' => array(
+ 'parent' => 'views_handler_field',
+ ),
),
);
}
diff --git a/views/filefield_handler_field_icon.inc b/views/filefield_handler_field_icon.inc
new file mode 100644
index 0000000..cecea83
--- /dev/null
+++ b/views/filefield_handler_field_icon.inc
@@ -0,0 +1,25 @@
+<?php
+/**
+ * @file
+ * Returns a file icon based on its MIME type.
+ */
+
+class filefield_handler_field_icon extends views_handler_field {
+ function construct() {
+ parent::construct();
+ $this->additional_fields['fid'] = 'fid';
+ $this->additional_fields['filename'] = 'filename';
+ $this->additional_fields['filesize'] = 'filesize';
+ }
+
+ function render($values) {
+ $value = $this->get_value($values);
+ $pseudo_file = array(
+ 'fid' => $this->get_value($values, 'fid'),
+ 'filemime' => $value,
+ 'filename' => $this->get_value($values, 'filename'),
+ 'filesize' => $this->get_value($values, 'filesize'),
+ );
+ return theme('filefield_icon', $pseudo_file);
+ }
+}