Closed (fixed)
Project:
Jquery Colorpicker
Version:
7.x-1.0-beta3
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 Feb 2012 at 16:36 UTC
Updated:
12 Apr 2012 at 13:40 UTC
I needed to put some colors in the rel tag of link using views. (eg. rel="ffdb6e,ffcc00") (this because they need to be handled by javascript later on).
I noticed the "text only" formatter also introduced html tags and a wrapper around #
So I created a quick patch with a raw hex formatter.
Might be usefull to someone so I decided to share it
@@ -307,7 +307,12 @@ function jquery_colorpicker_field_format
'label' => t('Text'),
'field types' => array('jquery_colorpicker'),
),
- );
+ 'jquery_colorpicker_raw_hex_display' => array
+ (
+ 'label' => t('Raw hex'),
+ 'field types' => array('jquery_colorpicker'),
+ ),
+ );
}
/**
@@ -315,24 +320,27 @@ function jquery_colorpicker_field_format
*/
function jquery_colorpicker_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display)
{
- $element = array();
- foreach($items as $delta => $item)
- {
- if($display['type'] == 'jquery_colorpicker_color_display')
- {
- $element[$delta]['#markup'] = '<div id="jquery_colorpicker_color_display_' . $instance['id'] . '_' . $delta . '_' . $item['jquery_colorpicker'] . '"> </div>';
- $element[$delta]['#attached']['css'][] = array
- (
- 'type' => 'inline',
- 'data' => '#jquery_colorpicker_color_display_' . $instance['id'] . '_' . $delta . '_' . $item['jquery_colorpicker'] . '{background-color:#' . $item['jquery_colorpicker'] . ';}',
- );
- }
- elseif($display['type'] == 'jquery_colorpicker_text_display')
- {
- $element[$delta]['#markup'] = '<div class="jquery_colorpicker_text_display"><span class="jquery_colorpicker_hash_mark">#</span>' . $item['jquery_colorpicker'] . '</div>';
- }
- }
- return $element;
+ $element = array();
+ foreach($items as $delta => $item)
+ {
+ switch ($display['type']) {
+ case 'jquery_colorpicker_color_display':
+ $element[$delta]['#markup'] = '<div id="jquery_colorpicker_color_display_' . $instance['id'] . '_' . $delta . '_' . $item['jquery_colorpicker'] . '"> </div>';
+ $element[$delta]['#attached']['css'][] = array
+ (
+ 'type' => 'inline',
+ 'data' => '#jquery_colorpicker_color_display_' . $instance['id'] . '_' . $delta . '_' . $item['jquery_colorpicker'] . '{background-color:#' . $item['jquery_colorpicker'] . ';}',
+ );
+ break;
+ case 'jquery_colorpicker_text_display':
+ $element[$delta]['#markup'] = '<div class="jquery_colorpicker_text_display"><span class="jquery_colorpicker_hash_mark">#</span>' . $item['jquery_colorpicker'] . '</div>';
+ break;
+ case 'jquery_colorpicker_raw_hex_display':
+ $element[$delta]['#markup'] = $item['jquery_colorpicker'];
+ break;
+ }
+ }
+ return $element;
}
/**
Comments
Comment #1
rv0 commentedhm something must have gone wrong when copypasting this patch..
the part where it starts is jquery_colorpicker_field_formatter_info()
sorry for that, needs some manual work.
This module isn't following drupal coding standards well btw..
Comment #2
plopescPatch committed with attribution.
Thanks for your interest.