summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filefield.module18
-rw-r--r--filefield_formatter.inc46
2 files changed, 64 insertions, 0 deletions
diff --git a/filefield.module b/filefield.module
index 93dcf39..3b1ab1e 100644
--- a/filefield.module
+++ b/filefield.module
@@ -89,6 +89,14 @@ function filefield_theme() {
'arguments' => array('element' => NULL),
'file' => 'filefield_formatter.inc',
),
+ 'filefield_formatter_url_plain' => array(
+ 'arguments' => array('element' => NULL),
+ 'file' => 'filefield_formatter.inc',
+ ),
+ 'filefield_formatter_path_plain' => array(
+ 'arguments' => array('element' => NULL),
+ 'file' => 'filefield_formatter.inc',
+ ),
'filefield_item' => array(
'arguments' => array('file' => NULL, 'field' => NULL),
'file' => 'filefield_formatter.inc',
@@ -364,6 +372,16 @@ function filefield_field_formatter_info() {
'multiple values' => CONTENT_HANDLE_CORE,
'description' => t('Displays all kinds of files with an icon and a linked file description.'),
),
+ 'path_plain' => array(
+ 'label' => t('Path to file'),
+ 'field types' => array('filefield'),
+ 'description' => t('Displays the file system path to the file.'),
+ ),
+ 'url_plain' => array(
+ 'label' => t('URL to file'),
+ 'field types' => array('filefield'),
+ 'description' => t('Displays a full URL to the file.'),
+ ),
);
}
diff --git a/filefield_formatter.inc b/filefield_formatter.inc
index dfe65bd..4e3593b 100644
--- a/filefield_formatter.inc
+++ b/filefield_formatter.inc
@@ -21,6 +21,52 @@ function theme_filefield_formatter_default($element) {
}
/**
+ * Theme function for the 'path_plain' formatter.
+ */
+function theme_filefield_formatter_path_plain($element) {
+ // Inside a View this function may be called with null data. In that case,
+ // just return.
+ if (empty($element['#item'])) {
+ return '';
+ }
+
+ $field = content_fields($element['#field_name']);
+ $item = $element['#item'];
+ // If there is no image on the database, use default.
+ if (empty($item['fid']) && $field['use_default_file']) {
+ $item = $field['default_file'];
+ }
+ if (empty($item['filepath']) && !empty($item['fid'])) {
+ $item = array_merge($item, field_file_load($item['fid']));
+ }
+
+ return empty($item['filepath']) ? '' : file_create_path($item['filepath']);
+}
+
+/**
+ * Theme function for the 'url_plain' formatter.
+ */
+function theme_filefield_formatter_url_plain($element) {
+ // Inside a View this function may be called with null data. In that case,
+ // just return.
+ if (empty($element['#item'])) {
+ return '';
+ }
+
+ $field = content_fields($element['#field_name']);
+ $item = $element['#item'];
+ // If there is no image on the database, use default.
+ if (empty($item['fid']) && $field['use_default_file']) {
+ $item = $field['default_file'];
+ }
+ if (empty($item['filepath']) && !empty($item['fid'])) {
+ $item = array_merge($item, field_file_load($item['fid']));
+ }
+
+ return empty($item['filepath']) ? '' : file_create_url($item['filepath']);
+}
+
+/**
* Theme function for any file that is managed by filefield.
* It doesn't really format stuff by itself but rather redirects to other
* formatters that are telling us they want to handle the concerned file.