Pārlūkot izejas kodu

project creation

bachy 13 gadi atpakaļ
revīzija
8ec280d5fa
3 mainītis faili ar 773 papildinājumiem un 0 dzēšanām
  1. 3 0
      tode.css
  2. 9 0
      tode.info
  3. 761 0
      tode.module

+ 3 - 0
tode.css

@@ -0,0 +1,3 @@
+.ctu-term-edit-form-box{border: 1px solid #ddd; padding:0.5em;}
+#node-form fieldset.tcu-advanced-options,
+#node-form fieldset.tcu-term-fields{width:45%; display:inline-block; vertical-align: top;}

+ 9 - 0
tode.info

@@ -0,0 +1,9 @@
+name = Tode
+description = First time this field will be used, it will create a new term with the value inserted in the textfield, after that, the term (tid) will always be the same, just update term name by updating the value of the field. You can keep synchronized a fixe term with a node, you can set an auto title from this field, The required, number of value at 1 and term_node synch of global field are required
+project = "Tode"
+dependencies[] = taxonomy
+dependencies[] = field
+package = gui
+version = "7.x-0.dev"
+core = "7.x"
+

+ 761 - 0
tode.module

@@ -0,0 +1,761 @@
+<?php
+
+
+/**
+ * developed by www.g-u-i.net
+ * 2011
+ * First time this field will be used, it will create a new term with the value inserted in the textfield, 
+ * after that, the term (tid) will always be the same, just update term name by updating the value of the field. 
+ * You can keep synchronized a fixe term with a node, 
+ * you can set an auto title from this field, The required, 
+ * number of value at 1 and term_node synch of global field are required
+ * 
+ * 
+ */
+
+/**
+ * Implementation of hook_menu().
+ */
+function tode_menu() {
+	$items = array();
+
+	// $items['node/%node/tode/%term'] = array(
+	//     'title' => 'Taxonomy Term',
+	//     'type' => MENU_LOCAL_TASK,
+	//     'access callback' => 'tode_node_tab_access',
+	//     'access arguments' => array(2),
+	//     'page callback' => 'tode_tab_page',
+	//     'page arguments' => array(2),
+	//     'file' => 'tode.pages.inc',
+	//     'weight' => 2,
+	//   );
+
+	return $items;
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function tode_theme() {
+	return array(
+		'tode' => array(
+			'arguments' => array('element' => NULL),
+		),
+	);
+}
+
+/**
+ * Implementation of hook_init().
+ */
+function tode_init() {
+	// File hooks and callbacks may be used by any module.
+	drupal_add_css(drupal_get_path('module', 'tode') .'/tode.css');
+}
+
+/**
+ * Implementation of hook_field_widget_info().
+ */
+# BUG PLUS
+function tode_field_widget_info() {
+	
+	return array(
+    'tode' => array(
+      'label' => t('Create update/change'),
+      'field types' => array('taxonomy_term_reference'),
+      'behaviors' => array(
+        'multiple values' => FIELD_BEHAVIOR_DEFAULT,
+				'default value' => FIELD_BEHAVIOR_NONE,
+      ),
+      'settings' => array(
+        'size' => 60,
+				'show_term_form'=> 0,
+				'maxlength'=> 255,
+      ),
+    ),
+  );
+	
+	# from taxonomy
+	// return array(
+	//     'taxonomy_autocomplete' => array(
+	//       'label' => t('Autocomplete term widget (tagging)'),
+	//       'field types' => array('taxonomy_term_reference'),
+	//       'settings' => array(
+	//         'size' => 60,
+	//         'autocomplete_path' => 'taxonomy/autocomplete',
+	//       ),
+	//       'behaviors' => array(
+	//         'multiple values' => FIELD_BEHAVIOR_CUSTOM,
+	//       ),
+	//     ),
+	//   );
+	//   
+}
+
+
+
+/**
+ * Implementation of hook_widget_settings
+ */
+#hook_field_widget_settings_form($field, $instance)
+function tode_field_widget_settings_form($field, $instance){
+	dsm($instance, 'tode_field_widget_settings_form : $instance');
+	dsm($field, 'field');
+	
+	$widget = $instance['widget'];
+  $settings = $widget['settings'];
+
+	
+		$form['tode'] = array(
+			'#type' => 'fieldset',
+			'#title' => t('Settings for terms'),
+			'#collapsible' => TRUE,
+			'#weight' => 10,
+			'#description' => t('First time this field will be used, it will create a new term with the value inserted in the textfield, after that, the term (tid) will always be the same, just update term name by updating the value of the field. You can keep synchronized a fixe term with a node, you can set an auto title from this field, The required, number of value at 1 and term_node synch of global field are required'),
+		);
+		
+		 
+		$form['tode']['maxlength'] = array(
+			'#type' => 'textfield', 
+			'#title' => t('Maximum length of term'), 
+			'#default_value' => $settings['maxlength'],
+			'#element_validate' => array('_tode_widget_settings_maxlength_validate'),
+			'#required' => TRUE,
+			'#description' => t('Defines how many characters can be typed into the text field. For values higher than 255, remember that one term name can not be longer than 255 (would be cutted).'),
+		);
+		 
+		$form['tode']['show_term_form'] = array(
+			'#type' => 'checkbox',
+			'#title' => t('Show taxonomy term edit form ?'),
+			'#default_value' => $settings['show_term_form'],
+		);
+		// 
+
+		/*
+			TODO active_tags : leave this in place because of the multi terms feature in the future
+		*/
+		// if (module_exists('active_tags')) {
+		//	 $form['update']['active_tags'] = array(
+		//		 '#type' => 'checkbox', 
+		//		 '#title' => t('Use Active Tags style widget'), 
+		//		 '#default_value' => isset($widget['active_tags']) ? $widget['active_tags'] : 0,
+		//		 '#description' => t('Use the Active Tags module to improve the usability of this autocomplete widget.'),
+		//	 );
+		// }
+
+		return $form;
+	
+}
+
+// function tode_form_content_field_edit_form_alter(&$form, &$form_state){
+// 	dsm('tode_form_content_field_edit_form_alter');
+// 	/*
+// 		TODO add the multi terms feature
+// 	*/
+// 	if($form['type']['#value'] == 'content_taxonomy' && $form['widget_module']['#value'] == 'tode'){
+// 		$form['field']['multiple']['#default_value'] = 0; // 0 here is 1 value for the cck field
+// 		$form['field']['multiple']['#prefix'] = '<div style="display:none">';
+// 		$form['field']['multiple']['#suffix'] = '</div>';
+// 	}
+// }
+
+function _tode_widget_settings_maxlength_validate($element, &$form_state) {
+	$value = $form_state['values']['maxlength'];
+	if (!is_numeric($value) || intval($value) != $value || $value <= 0) {
+		form_error($element, t('"Maximum length" must be a positive integer.'));
+	}
+}
+
+/**
+ * Implementation of FAPI hook_elements().
+ *
+ * Any FAPI callbacks needed for individual widgets can be declared here,
+ * and the element will be passed to those callbacks for processing.
+ *
+ * Drupal will automatically theme the element using a theme with
+ * the same name as the hook_elements key.
+ *
+ * Autocomplete_path is not used by text_widget but other widgets can use it
+ * (see nodereference and userreference).
+ * 
+ * http://drupal.org/node/224333#hook_element_info
+ * 
+ */
+#hook_element_info()
+function tode_element_info() {
+	return array(
+	 'tode' => array(
+		 '#input' => TRUE,
+		 '#columns' => array('value'), 
+		 '#delta' => 0,
+		 '#process' => array('tode_element_process'),
+		 ),
+	 );
+}
+
+/**
+ * Implementation of hook_field_widget_form().
+ */
+function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
+	dsm('tode_field_widget_form');
+	dsm($items, 'items');
+	dsm($element, '$element');
+	/*
+		$element['#entity_type']
+		$element['#bundle']
+		$element['#field_name']
+		$element['#language']
+		$element['#columns']
+		$element['#title']
+		$element['#description']
+		$element['#required']
+		$element['#delta']
+		$element['#language']
+	*/
+	
+	# thats the original D6 $element
+	// $element = array(
+	// 	'#type' => 'tode',
+	// 	'#default_value' => isset($items) ? $items : NULL,
+	// 	'#vid' => $field['vid'],
+	// );
+	
+	# example
+	//   // use += to avoid overwriting incoming $element
+	//   $element['value'] += array(
+	//     // Fill in $element.
+	//   );
+	
+ // $tags = array();
+ //  foreach ($items as $item) {
+ //    $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
+ //  }
+	
+	$term_name = '';
+	$term_tid = 0;
+	
+	if(count($items)){
+		$term = isset($items[0]['taxonomy_term']) ? $items[0]['taxonomy_term'] : taxonomy_term_load($items[0]['tid']);
+		$term_name = $term->term_name;
+		$term_tid = $term->tid;
+	}
+
+	$element['tode_tid'] = array('#type' => 'hidden', '#value' => $term_tid,'#delta' => $element['#delta'],);
+		
+  $element += array(
+    '#type' => 'textfield',
+    '#default_value' => $term_name,
+    '#size' => $instance['widget']['settings']['size'],
+    '#maxlength' => $instance['widget']['settings']['maxlength'],
+    '#element_validate' => array('tode_validate'),
+  );
+	
+	# add the term edit form
+	// if(isset($value))
+	// 	_tode_add_term_form($element, $term, $widget['show_term_form']);
+	
+  return $element;
+}
+
+
+/**
+ * Process an individual element.
+ *
+ * Build the form element. When creating a form using FAPI #process,
+ * note that $element['#value'] is already set.
+ *
+ */
+# OLD NOT USED ANY MORE, TRANSPOSE THIS CODE (ALL OR PART) ON hook_field_widget_form();
+function tode_element_process($element, $edit, $form_state, $form) {
+	// dsm('tode widget process');
+	// dsm($form, 'form');
+	// dsm($element, 'element');
+
+	$field_name = $element['#field_name'];
+	$field = $form['#field_info'][$field_name];
+	$field_key	= $element['#columns'][0];
+	// dsm($field);
+	$widget = $field['widget'];
+
+	$value = NULL;
+	if (count($element['#default_value'])) {
+		$term = taxonomy_get_term($element['#default_value'][0][$field_key]);
+		// dsm($term);
+		$value = $term->name;
+	}
+	
+	# converting the tid to term name on visible value oh the text field, we re-convert terma name to tid on the validat function
+	$element['#default_value'][0][$field_key] = $value;
+	$element['#value'][$field_key] = $value;
+	
+	# memorize the tid for the validate function
+	if($value)
+		$element['tode_tid'] = array('#type' => 'hidden', '#value' => $term->tid,'#delta' => $element['#delta'],);
+	
+	$element[$field_key] = array(
+		'#type' => 'textfield',
+		'#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '',
+		'#title' => $element['#title'],
+		'#required' => $element['#required'],
+		'#description' => $element['#description'],
+		'#field_name' => $element['#field_name'],
+		'#type_name' => $element['#type_name'],
+		'#delta' => $element['#delta'],
+		'#columns' => $element['#columns'],
+		'#maxlength' => !empty($field['widget']['maxlength']) ? $field['widget']['maxlength'] : 255,
+	);
+
+	# add the term edit form
+	if(isset($value))
+		_tode_add_term_form($element, $term, $widget['show_term_form']);
+	
+	# add validation for the fieldform to retrive tid instead of term name (content taxonomy module), As i know we can't add a submit callback to the form from the widget
+	if (empty($element[$field_key]['#element_validate']))
+		$element[$field_key]['#element_validate'] = array();
+	// 
+	array_unshift($element[$field_key]['#element_validate'], 'tode_validate');
+	# replace validate with submit added on form alter
+	
+	// dsm($form_state, 'form_state');
+	// dsm($element, 'element');
+
+	return $element;
+}
+
+
+
+/**
+ * _tode_add_term_form($term)
+ * 
+ */
+function _tode_add_term_form(&$element, $term, $show){
+	module_load_include('inc', 'taxonomy', 'taxonomy.admin');
+	
+	$term_form = _tode_term_form($term->tid);
+	// dsm($term_form, 'term_form');
+	
+	if($term_form){
+		
+		$term_form['identification']['#prefix'] = '<div style="display:none;">';
+		$term_form['identification']['#suffix'] = '</div>';
+		$term_form['advanced']['synonyms']['#prefix'] = '<div style="display:none;">';
+		$term_form['advanced']['synonyms']['#suffix'] = '</div>';
+		$term_form['advanced']['weight']['#prefix'] = '<div style="display:none;">';
+		$term_form['advanced']['weight']['#suffix'] = '</div>';
+		$term_form['advanced']['parent']['#prefix'] = '<div style="display:none;">';
+		$term_form['advanced']['parent']['#suffix'] = '</div>';
+		$term_form['advanced']['relations']['#prefix'] = '<div style="display:none;">';
+		$term_form['advanced']['relations']['#suffix'] = '</div>';
+
+		# change appearence of adavnced fiedset to show both fiedlset inline
+		$term_form['advanced']['#collapsible'] = FALSE;
+		$term_form['fields']['#collapsible'] = FALSE;
+		
+		_tode_trim_options($term_form, 'advanced');
+		$term_form['advanced']['#attributes'] = array('class'=>'tcu-advanced-options');
+		$term_form['fields']['#attributes'] = array('class'=>'tcu-term-fields');
+		
+		foreach($term_form['fields'] as $field_name => $field){
+			if($field['#type'] == 'textfield')
+				$field['#size'] = 30;
+				
+			$term_form['fields'][$field_name] = $field;
+		}
+
+		unset($term_form['submit']);
+		unset($term_form['delete']);
+		
+		#unset vid info 'cause is in conflict with the node's vid field
+		// unset($term_form['vid']);
+
+		$element['term_form'] = array(
+			'#type' => 'fieldset',
+			'#title' => t('Term edit'),
+			'#tree' => TRUE,
+			'#collapsible' => TRUE,
+			'#collapsed' => FALSE,
+			'#weight'=>1,
+			'#group'=>'additional_settings',
+		);
+		
+		if(!$show){
+			$element['term_form']['#prefix'] = '<div style="display:none;">';
+			$element['term_form']['#suffix'] = '</div>';
+		}
+
+		$term_form = _tode_prefix_form($term_form, 'tode_termform_'.$element['#field_name'].'_');
+
+		$element['term_form'] += $term_form;
+		
+		$element['tode_termform'] = array('#type' => 'hidden', '#value' => 'true','#delta' => $element['#delta'],);
+		
+		// $element['#prefix'] = '<div class="tode-term-edit-form-box">';
+		// $element['#suffix'] = '</div>';
+
+		// dsm($element, 'element');
+	}
+
+}
+
+
+/**
+ * Validation function for the tode element
+ *
+ * parses input and sets the values as needed (tid) for storing the data
+ */
+function tode_validate($element, &$form_state){
+	dsm('tode_validate');
+	dsm($form_state, 'form_state');
+	dsm($element, 'element');
+
+ 	$value = array();
+  if ($typed_term = $element['#value']) {
+		$field = field_widget_field($element, $form_state);
+		dsm($field, 'field');
+
+    $vocabularies = array();
+    foreach ($field['settings']['allowed_values'] as $tree) {
+      if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) {
+        $vocabularies[$vocabulary->vid] = $vocabulary;
+      }
+    }
+		
+		
+		
+		
+		// See if the term exists in the chosen vocabulary and return the tid;
+    // otherwise, create a new 'autocreate' term for insert/update.
+		if($tid = $element['tode_tid']['#value']){
+			$term = taxonomy_term_load($tid);
+		}else{
+			$vocabulary = reset($vocabularies);
+			$term = array(
+        'tid' => 'autocreate',
+        'vid' => $vocabulary->vid,
+        'name' => $typed_term,
+        'vocabulary_machine_name' => $vocabulary->machine_name,
+      );
+		}
+		
+		dsm($term, '$term');
+		
+		$value[] = (array)$term;
+	
+	}
+	dsm($value, '$value');
+  form_set_value($element, $value, $form_state);
+
+
+	// $field_name = $element['#field_name'];
+	//   $field = content_fields($field_name, $element['#type_name']);
+	//   $field_key  = $element['#columns'][0];
+	// 
+	// #if the element parents array contains the field key, we have to remove it
+	//   #because otherwise form_set_value won't work. (still the question why is it in)
+	//   if ($element['#parents'][count($element['#parents'])-1] == $field_key) {
+	//     array_pop($element['#parents']);
+	//     array_pop($element['#array_parents']);
+	//   }
+	// 
+	// $term_name = $element['#value'] != '' ? $element['#value'] : ($element['#default_value'] != '' ? $element['#default_value'] : NULL);
+	// // dsm($term_name, 'term_name');
+	// $form_state['values']['tode_termform_'.$field_name.'_name'] = $term_name;
+	// 
+	// $tid = isset($form_state['values'][$field_name]['tode_tid']) ? $form_state['values'][$field_name]['tode_tid'] : NULL;
+	// // dsm($tid, 'tid');
+	// $value = array();
+	// if($tid){
+	// 	$value[$tid] = $tid;
+	// }else{
+	// 	# if no tid it says that we create a node so a term
+	// 	$term = array(
+	// 		"vid" => $field['vid'],
+	// 		"name" => $term_name,
+	// 		"parent" => $field['widget']['extra_parent'] ? $field['widget']['extra_parent'] : content_taxonomy_field_get_parent($field),
+	// 	);
+	// 	$status = taxonomy_save_term($term);
+	// 	$value[$term['tid']] = $term['tid'];
+	// }
+	// 
+	// $values = content_transpose_array_rows_cols(array($element['#columns'][0] => $value));
+	// // dsm($values, 'values');
+	// form_set_value($element, $values, $form_state);
+	// 
+	// // dsm($element, 'element');
+	// // dsm($form_state, 'form_state');
+
+  // form_set_value($element, $value, $form_state);
+}
+
+/**
+ * Implements hook_field_widget_error().
+ */
+function tode_field_widget_error($element, $error, $form, &$form_state) {
+	# use this to set errors
+	form_error($element['value'], $error['message']);
+}
+
+/**
+ * implementation of hook_nodeapi()
+ * 
+ * process the tode term on node create or update
+ * we make this on nodeapi cause we can't cache field save from a widget … mayde in D7
+ * 
+ */
+/*
+	TODO add term translation feature
+*/
+
+function tode_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
+	// dsm($op, 'tode nodeapi : op');
+	switch($op){
+		// case 'presave':
+		case 'update':
+			// tode_save($node);
+			break;
+	}
+}
+
+/**
+ * submit values
+ */
+function tode_save($node) {
+	
+	module_load_include('inc', 'taxonomy', 'taxonomy.admin');
+	
+	// dsm('tode save');
+	// dsm($node, 'tode submit : node');
+
+	$tode_fields = _tode_get_tode_fields_def($node->type);
+	
+	if(!count($tode_fields))
+		return;
+		
+	foreach ($tode_fields as $field_name => $field) {
+		$values = array();
+		$prefix = 'tode_termform_'.$field_name.'_';
+		foreach ($node as $key => $value) {
+			if(strpos($key, $prefix) !== FALSE)
+				$values[$key] = $value;
+		}
+		// dsm($values, 'values');
+		$values = _tode_prefix_form($values, $prefix, FALSE);
+		// dsm($values, 'values');
+		
+		$array_term = (array)taxonomy_get_term($values['tid']);
+		
+		foreach ($values as $key => $value) {
+			if(is_array($value))
+				$values += $value;
+		}
+		
+		$array_term = (array)taxonomy_get_term($values['tid']);
+		
+		// dsm($values, 'values');
+		
+		$form_state = array();
+		$form_state['values']	= $values;
+		$form_state['values']['op'] = t('Save');
+		
+		// dsm($form_state, 'form_state');
+			  
+		drupal_execute('taxonomy_form_term', $form_state, taxonomy_vocabulary_load($array_term['vid']), $array_term);
+		
+	}
+}
+
+
+/**
+ * theme_tode
+ * 
+ */
+function theme_tode($element) {
+	return $element['#children'];
+}
+
+
+
+
+/**
+ * Implementation of hook_form_alter().
+ * 
+ * node deletion to delete also the tode term
+ * 
+ */
+function tode_form_alter(&$form, $form_state, $form_id){
+	
+	if (stripos($form_id, 'node_delete_confirm') !== false){
+		// dsm($form_id, 'tode form_alter form_id');
+		/*
+			TODO test deletion
+		*/
+		_tode_node_delete_form_alter($form, $form_state);
+		// dsm($form);
+	}
+
+}
+
+
+function _tode_node_delete_form_alter(&$form){
+	// dsm($form, '_tode_node_delete_form_alter : form');
+	#get the node
+	$node = $form['#parameters'][2];
+	// dsm($node);
+	
+	# why that tnid ???
+	// if($node->tnid != 0)
+	// 	return;
+
+	#get the fields defenition of node type
+	$tode_fields = _tode_get_tode_fields_def($node->type);
+	//dsm($tode_fields);
+	
+	if(count($tode_fields) == 0)
+		return;
+
+	#get the terms value
+	$terms = array();
+	$tids = array();
+	foreach ($tode_fields as $field_name => $field) {
+		foreach ($node->$field_name as $term) {
+			$term = taxonomy_get_term($term['value']);
+			$terms[] = $term->name;
+			$tids[] = $term->tid;
+		}
+	}
+
+	if(count($terms)){
+		/*
+			TODO add here a checkbox to select terms to delete
+		*/
+		#add some warning in form description
+		$form['description']['#value'] .= '<br />'.t('this will also delete taxonomy terms : %terms', array('%terms'=>implode(', ', $terms)));
+
+		$form['tode_delete'] = array( '#type' => 'hidden', '#value' => serialize($tids),);
+
+		$form['tode_terms'] = array('#type' => 'hidden', '#value' => serialize($terms),);
+
+		$form['#submit'][] = 'tode_delete_submit';
+	}
+	
+
+
+}
+
+
+function tode_delete_submit($form, &$form_state){
+	$tids = unserialize($form['tode_delete']['#value']);
+	foreach ($tids as $tid)
+		taxonomy_del_term($tid);
+		
+	$terms = unserialize($form['tode_terms']['#value']);	
+	drupal_set_message(t('Following Taxonomy terms have been deleted : %terms', array('%terms' => implode(', ', $terms) )), 'status');
+}
+
+
+
+/**
+ * HELPERS 
+ */
+// 
+// function _tode_prefix_keys($k){
+// 	if(strpos('#', $kk) == false)
+// 		return $prefix.$k;
+// }
+
+
+function _tode_clean_form($form){
+	foreach ($form as $key => $value) {
+		if(strpos($key,'#') !== false){
+			unset($form[$key]);			
+		}elseif(is_array($value)){
+			$form[$key] = _tode_clean_form($value);			
+		}
+	}
+	return $form;
+}
+
+function _tode_prefix_form($form, $prefix = '', $add = TRUE){
+	
+	foreach ($form as $key => $value) {
+		if(strpos($key,'#') === false){
+
+			if($value['#type'] == 'fieldset' || (!$add && is_array($value)))
+				$value = _tode_prefix_form($value, $prefix, $add);
+				
+			if($add){
+				$form[$prefix.$key] = $value;
+				unset($form[$key]);
+			}elseif(strpos($key, $prefix) !== false ){
+				$form[str_replace($prefix, '', $key)] = $value;
+				unset($form[$key]);
+			}
+			
+		}
+	}
+	
+	return $form;
+}
+
+/**
+ * _tode_term_form($tid)
+ * 
+ */
+function _tode_term_form($tid){
+	
+	if ($array_term = (array)taxonomy_get_term($tid)) {
+		
+		$form_state = array();
+		$term_form = drupal_retrieve_form('taxonomy_form_term', $form_state, taxonomy_vocabulary_load($array_term['vid']), $array_term);
+		drupal_prepare_form('taxonomy_form_term', $term_form, $form_state);
+		
+		return $term_form;
+	}else{
+		return false;
+	}
+	
+}
+
+/**
+ * _tode_trim_options(&$form, $element)
+ * 
+ */
+function _tode_trim_options(&$form, $item){
+	foreach ($form[$item] as $field_name => $field) {
+		if(((is_array($field)) && $field['#type'] == 'select') && $field['#multiple']){
+			$options = $field['#options'];
+			for ($i=0; $i < count($options); $i++) { 
+				if(!isset($options[$i]->option)) 
+					continue;
+					
+				$op = array();
+				foreach ($options[$i]->option as $key => $value)
+						$op[$key] = strlen($value) > 25 ? substr_replace ($value, ' [...] ', 15, -10) : $value; // affiche 'abc...xyz'
+						
+				$options[$i]->option = $op;
+			}
+			$field['#options'] = $options;
+			$form[$item][$field_name] = $field;
+		}
+	}
+}
+
+/**
+ * 
+ */
+function _tode_get_tode_fields_def($type){
+	// dsm($type, '_tode_get_fields_def');
+
+	#get the fields defenition of node type
+	$type_fields = content_types($type);
+	// dsm($type_fields, 'type_fields definition');
+
+	#get the tode node fields
+	$tode_fields = array();
+	foreach ($type_fields['fields'] as $field_name => $field) {
+		if($field['widget']['type'] == 'tode')
+			$tode_fields[$field_name] = $field;
+	}
+
+
+	return $tode_fields;
+}