Closed (fixed)
Project:
Term Fields
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Jul 2011 at 13:30 UTC
Updated:
2 Nov 2011 at 18:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
carvalhar commentedhi,
i looked at the code, but i'm still insecure of how to do it.
Can someone explain me how to add it?
i can post a patch or submodule after done.
thanks
Comment #2
b-prod commentedHi!
The term field module does not support extending fields currently. There is no hook to add a new field definition.
So you have to modify the code in different locations, which could be quite complicated.
If you provide a patch, I can test and review it and maybe correct it if necessary.
Ideally, the whole code should be rewrited, but since D7 handles term fields directly in core, it is not so interesting to continue improving this D6 module.
Comment #3
carvalhar commentedHi, I had to hack the module code, but i created this field. Actually i did it with two versions ;)
Here is my "how to", i would be glad if you add this functionality to the module.
There are two versions, one with Colorpicker Module:
http://drupal.org/project/colorpicker
And the other with jQuery Colorpicker
http://drupal.org/project/jquery_colorpicker
Both work fine, you need to choose a module and install it.
1) term_fields.admin.inc
Add this line above line 80: 'colorpicker' => t('Colorpicker'),
Code complete:
$form['type'] = array(
'#type' => 'radios',
'#title' => t('Field type'),
'#options' => array(
'checkbox' => t('Checkbox'),
'date' => t('Date'),
'file' => t('File'),
'numeric' => t('Integer'),
'select' => t('Select list'),
'colorpicker' => t('Colorpicker'), //ADD THIS LINE
'textarea' => t('Text area (multiple rows)'),
'textfield' => t('Text field'),
),
2)term_fields.module
Line 144: (search for term_fields_form_taxonomy_form_term_alter)
Add a case for colorpicker, just remember to chose the correct module. You just need to install one module and one code from the two below:
a) Jquery Colorpicker module:
case 'colorpicker':
$form['fields'][$fid] = array(
'#type' => 'colorpicker',
'#title' => t('Color picker textfield'),
'#description' => t('Please enter a color value in the form #RRGGBB'),
'#default_value' => $value || $value == 0 ? $value : '#000000',
);
b) Colorpicker module:
case 'colorpicker':
$color_field_type = (function_exists('colorpicker_2_or_later') ? 'colorpicker_' : '') .'textfield';
$form['fields'][$fid] = array(
'#type' => $color_field_type,
'#title' => t('Color picker textfield'),
'#description' => t('Please enter a color value in the form #RRGGBB'),
'#default_value' => $value || $value == 0 ? $value : '#000000',
);
3)term_fields.module
Line 777 (more or less), search for "function term_fields_get_db_conf"
switch ($type) {
case 'checkbox':
$result = array('type' => 'int', 'size' => 'tiny', 'default' => 0);
break;
case 'textfield':
case 'textarea':
case 'select':
case 'colorpicker': // ADD THIS LINE
$result = array('type' => 'text', 'size' => 'big');
break;
case 'numeric':
case 'file':
$result = array('type' => 'int');
break;
case 'date':
$result = array('type' => 'datetime');
break;
}
return $result;
}
Comment #4
b-prod commentedIf you cannot create a patch file, could you please send me your modified files in a zip archive? You have to make your changes against the DEV version.
Comment #5
carvalhar commentedHi,
I'm sending the custom code attached.
It's the dev module with the code that i described at #3
Comment #6
fastforward commentedThank you, carvalhar! I've just searched for something like this! This is really great improvement for Term Fields module. I've added Colorpicker values for taxonomy terms in admin/content/taxonomy/edit/term/... It's work like a charm at admin side. But why Colorpicker field type not showing in Views? I can reach Select List or even File via Views - Fields - Term Fields, but no Colorpicker field!
Comment #7
carvalhar commentedI also had this same issue when i was getting the value as a field from views.
I forgot to post here, sorry :/
You need to edit one line at term_fields.views.inc, at line 29, or search for this code:
switch ($record->type) {
case 'textfield':
$data['term_fields_term'][$fid] = array(
than add the colorpicker field for views:
switch ($record->type) {
case 'textfield':
case 'colorpicker': //line added
$data['term_fields_term'][$fid] = array(
[...]
Then you'll get a field who provides the color as a text (without "#").
bye
Comment #8
fastforward commentedText only? I think not only the text)) Now we can add Field "Term Fields: colorpicker_field", make it hidden. Then add Field "Customfield: Markup" (Views_Custom_Field module) with value like
<div style="background-color: [colorpicker_field]">[colorpicker_field]</div>(Input format: Full HTML) and voila - we have true colors in node view. Cool. Thank you once again!Comment #9
b-prod commentedSorry if I am not very present for your issue, but I intend to work soon on a 2.x version of term field which fixes lots of problems due to the way the module was first implemented.
I contemplate to expose some hooks that allow to quite easily create new fields.
Comment #10
carvalhar commented@fastforward
The views field for colorpicker can return a value with "#", but it's necessary to build a custom term_fields_handler_field include file. I don't know how to build one, maybe it's easy, but i don't know how.
Everything about this matter would be like a copy of textfield but addin a "#" character, I suppose.
You need to pay attention that the field can't return a tag, for example, in my case i used the color for the color for a link not for a div background.
@B-Proud
The module Service Links have an easy way to create new services. I think it would be a good reference for you to create new fields as sub modules.
bye
Carlos
Comment #11
carvalhar commentedhi,
I'm sending a patch against 6.x-1.x-dev to add this new feature.
The code checks if user has installed Jquery Colorpicker or Colorpicker. If both aren't installed, a new colorpicker field is still added, but it'll act as a normal and simple textfield.
It's possible also to get this field at views.
I'm uploading also 4 images with all 3 possibilities and a views setup.
To get the term field for colorpicker at views you can use "Rewrite the output of this field" to add the "#" character. At database, the color is stored as plain numeric text, eg.: 000000 for #000000
bye
Carlos
Comment #12
b-prod commentedSuch feature has been added in the 2.x DEV version, needing now some testing. Please read the release notes before upgrading, the 2.x DEV version is not currently ready for production environment.