summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Feenstra2012-10-04 00:09:33 (GMT)
committer Bart Feenstra2012-10-04 00:09:33 (GMT)
commitf7b4cc3142b5aed8b0bceb1d31dfc5fb75c6f786 (patch)
treeb760d62f4681ceb0b5cd96c2072fa7b461eaff48
Initial commit.
-rw-r--r--vase.info4
-rw-r--r--vase.install16
-rw-r--r--vase.module75
3 files changed, 95 insertions, 0 deletions
diff --git a/vase.info b/vase.info
new file mode 100644
index 0000000..b89d4e7
--- /dev/null
+++ b/vase.info
@@ -0,0 +1,4 @@
+name = Value Selection Field Formatter
+description = Allows every field formatter to only display a specified selection of a field's values.
+core = 7.x
+dependencies[] = field \ No newline at end of file
diff --git a/vase.install b/vase.install
new file mode 100644
index 0000000..2a5a85b
--- /dev/null
+++ b/vase.install
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * Installation and uninstallation functions.
+ */
+
+/**
+ * Implements hook_enable().
+ */
+function vase_enable() {
+ $weight = db_query("SELECT MAX(weight) FROM {system}")->fetchField() + 1;
+ db_query("UPDATE {system} SET weight = :weight WHERE name = :name", array(
+ ':weight' => $weight,
+ ':name' => 'vase',
+ ));
+} \ No newline at end of file
diff --git a/vase.module b/vase.module
new file mode 100644
index 0000000..af83043
--- /dev/null
+++ b/vase.module
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * Hook implementations and shared functions.
+ */
+
+/**
+ * Implements hook_field_formatter_info_alter().
+ */
+function vase_field_formatter_info_alter(array &$info) {
+ foreach ($info as $name => &$formatter) {
+ $formatter['settings']['vase_original_module'] = $formatter['module'];
+ $formatter['settings']['vase_offset'] = '0';
+ $formatter['settings']['vase_length'] = '0';
+ $formatter['module'] = 'vase';
+ }
+}
+
+/**
+ * Implements hook_field_formatter_settings_summary().
+ */
+function vase_field_formatter_settings_summary(array $field, array $instance, $view_mode) {
+ $display = $instance['display'][$view_mode];
+ $settings = $display['settings'];
+
+ return t('!original_summary (Offset: !offset. Length: !length)', array(
+ '!original_summary' => module_invoke($settings['vase_original_module'], 'field_formatter_settings_summary', $field, $instance, $view_mode),
+ '!offset' => $settings['vase_offset'],
+ '!length' => $settings['vase_length'] == 0 ? t('unlimited') : $settings['vase_length'],
+ ));
+}
+
+/**
+ * Implements hook_field_formatter_settings_form().
+ */
+function vase_field_formatter_settings_form(array $field, array $instance, $view_mode, array $form, array &$form_state) {
+ $display = $instance['display'][$view_mode];
+ $settings = $display['settings'];
+
+ $elements['vase_offset'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Offset'),
+ '#default_value' => $settings['vase_offset'],
+ '#element_validate' => array('element_validate_integer'),
+ '#size' => 9,
+ '#required' => TRUE,
+ );
+ $elements['vase_length'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Length'),
+ '#description' => t('Enter 0 for <em>unlimited</em>.'),
+ '#default_value' => $settings['vase_length'],
+ '#element_validate' => array('element_validate_integer'),
+ '#size' => 9,
+ '#required' => TRUE,
+ );
+ if (module_hook($settings['vase_original_module'], 'field_formatter_settings_form')) {
+ $function = $settings['vase_original_module'] . '_field_formatter_settings_form';
+ $elements = array_merge($function($field, $instance, $view_mode, $form, $form_state), $elements);
+ }
+
+ return $elements;
+}
+
+/**
+ * Implements hook_field_formatter_view().
+ */
+function vase_field_formatter_view($entity_type, $entity, array $field, array $instance, $langcode, array $items, $display) {
+ $settings = $display['settings'];
+
+ $length = $settings['vase_length'] == 0 ? NULL : $settings['vase_length'];
+ $items = array_slice($items, $settings['vase_offset'], $length);
+
+ return module_invoke($settings['vase_original_module'], 'field_formatter_view', $entity_type, $entity, $field, $instance, $langcode, $items, $display);
+} \ No newline at end of file