From 8ec280d5fa6321f2a9fbccc67f523d3b918c666b Mon Sep 17 00:00:00 2001 From: bachy Date: Thu, 25 Aug 2011 21:26:47 +0200 Subject: [PATCH 01/24] project creation --- tode.css | 3 + tode.info | 9 + tode.module | 761 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 773 insertions(+) create mode 100644 tode.css create mode 100644 tode.info create mode 100644 tode.module diff --git a/tode.css b/tode.css new file mode 100644 index 00000000..0d82149b --- /dev/null +++ b/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;} \ No newline at end of file diff --git a/tode.info b/tode.info new file mode 100644 index 00000000..26506a0f --- /dev/null +++ b/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" + diff --git a/tode.module b/tode.module new file mode 100644 index 00000000..5ff7d1c4 --- /dev/null +++ b/tode.module @@ -0,0 +1,761 @@ + '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'] = '
'; +// $form['field']['multiple']['#suffix'] = '
'; +// } +// } + +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'] = '
'; + $term_form['identification']['#suffix'] = '
'; + $term_form['advanced']['synonyms']['#prefix'] = '
'; + $term_form['advanced']['synonyms']['#suffix'] = '
'; + $term_form['advanced']['weight']['#prefix'] = '
'; + $term_form['advanced']['weight']['#suffix'] = '
'; + $term_form['advanced']['parent']['#prefix'] = '
'; + $term_form['advanced']['parent']['#suffix'] = '
'; + $term_form['advanced']['relations']['#prefix'] = '
'; + $term_form['advanced']['relations']['#suffix'] = '
'; + + # 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'] = '
'; + $element['term_form']['#suffix'] = '
'; + } + + $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'] = '
'; + // $element['#suffix'] = '
'; + + // 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'] .= '
'.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; +} From 951be207ab011c1d781995b36b29586509211d47 Mon Sep 17 00:00:00 2001 From: bachy Date: Thu, 25 Aug 2011 21:32:15 +0200 Subject: [PATCH 02/24] add readme --- readme.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 readme.txt diff --git a/readme.txt b/readme.txt new file mode 100644 index 00000000..cad2ab58 --- /dev/null +++ b/readme.txt @@ -0,0 +1 @@ +!!! this module is not ready tu use !!! \ No newline at end of file From ad30a381f98b99f2f7f931e68b22b145ea8312cb Mon Sep 17 00:00:00 2001 From: bachy Date: Sun, 28 Aug 2011 11:09:59 +0200 Subject: [PATCH 03/24] no message --- LICENSE.txt | 274 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.txt | 1 + 2 files changed, 275 insertions(+) create mode 100644 LICENSE.txt create mode 100644 README.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 00000000..2c095c8d --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,274 @@ +GNU GENERAL PUBLIC LICENSE + + Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, +Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute +verbatim copies of this license document, but changing it is not allowed. + + Preamble + +The licenses for most software are designed to take away your freedom to +share and change it. By contrast, the GNU General Public License is +intended to guarantee your freedom to share and change free software--to +make sure the software is free for all its users. This General Public License +applies to most of the Free Software Foundation's software and to any other +program whose authors commit to using it. (Some other Free Software +Foundation software is covered by the GNU Library General Public License +instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our +General Public Licenses are designed to make sure that you have the +freedom to distribute copies of free software (and charge for this service if +you wish), that you receive source code or can get it if you want it, that you +can change the software or use pieces of it in new free programs; and that +you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to +deny you these rights or to ask you to surrender the rights. These restrictions +translate to certain responsibilities for you if you distribute copies of the +software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for +a fee, you must give the recipients all the rights that you have. You must make +sure that they, too, receive or can get the source code. And you must show +them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) +offer you this license which gives you legal permission to copy, distribute +and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that +everyone understands that there is no warranty for this free software. If the +software is modified by someone else and passed on, we want its recipients +to know that what they have is not the original, so that any problems +introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We +wish to avoid the danger that redistributors of a free program will individually +obtain patent licenses, in effect making the program proprietary. To prevent +this, we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification +follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND + MODIFICATION + +0. This License applies to any program or other work which contains a notice +placed by the copyright holder saying it may be distributed under the terms +of this General Public License. The "Program", below, refers to any such +program or work, and a "work based on the Program" means either the +Program or any derivative work under copyright law: that is to say, a work +containing the Program or a portion of it, either verbatim or with +modifications and/or translated into another language. (Hereinafter, translation +is included without limitation in the term "modification".) Each licensee is +addressed as "you". + +Activities other than copying, distribution and modification are not covered +by this License; they are outside its scope. The act of running the Program is +not restricted, and the output from the Program is covered only if its contents +constitute a work based on the Program (independent of having been made +by running the Program). Whether that is true depends on what the Program +does. + +1. You may copy and distribute verbatim copies of the Program's source +code as you receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice and +disclaimer of warranty; keep intact all the notices that refer to this License +and to the absence of any warranty; and give any other recipients of the +Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you +may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, +thus forming a work based on the Program, and copy and distribute such +modifications or work under the terms of Section 1 above, provided that you +also meet all of these conditions: + +a) You must cause the modified files to carry prominent notices stating that +you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in whole or in +part contains or is derived from the Program or any part thereof, to be +licensed as a whole at no charge to all third parties under the terms of this +License. + +c) If the modified program normally reads commands interactively when run, +you must cause it, when started running for such interactive use in the most +ordinary way, to print or display an announcement including an appropriate +copyright notice and a notice that there is no warranty (or else, saying that +you provide a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this License. +(Exception: if the Program itself is interactive but does not normally print such +an announcement, your work based on the Program is not required to print +an announcement.) + +These requirements apply to the modified work as a whole. If identifiable +sections of that work are not derived from the Program, and can be +reasonably considered independent and separate works in themselves, then +this License, and its terms, do not apply to those sections when you distribute +them as separate works. But when you distribute the same sections as part +of a whole which is a work based on the Program, the distribution of the +whole must be on the terms of this License, whose permissions for other +licensees extend to the entire whole, and thus to each and every part +regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest your rights to +work written entirely by you; rather, the intent is to exercise the right to +control the distribution of derivative or collective works based on the +Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of a +storage or distribution medium does not bring the other work under the scope +of this License. + +3. You may copy and distribute the Program (or a work based on it, under +Section 2) in object code or executable form under the terms of Sections 1 +and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable source +code, which must be distributed under the terms of Sections 1 and 2 above +on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three years, to give +any third party, for a charge no more than your cost of physically performing +source distribution, a complete machine-readable copy of the corresponding +source code, to be distributed under the terms of Sections 1 and 2 above on +a medium customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer to distribute +corresponding source code. (This alternative is allowed only for +noncommercial distribution and only if you received the program in object +code or executable form with such an offer, in accord with Subsection b +above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source code +means all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation and +installation of the executable. However, as a special exception, the source +code distributed need not include anything that is normally distributed (in +either source or binary form) with the major components (compiler, kernel, +and so on) of the operating system on which the executable runs, unless that +component itself accompanies the executable. + +If distribution of executable or object code is made by offering access to +copy from a designated place, then offering equivalent access to copy the +source code from the same place counts as distribution of the source code, +even though third parties are not compelled to copy the source along with the +object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as +expressly provided under this License. Any attempt otherwise to copy, +modify, sublicense or distribute the Program is void, and will automatically +terminate your rights under this License. However, parties who have received +copies, or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. +However, nothing else grants you permission to modify or distribute the +Program or its derivative works. These actions are prohibited by law if you +do not accept this License. Therefore, by modifying or distributing the +Program (or any work based on the Program), you indicate your acceptance +of this License to do so, and all its terms and conditions for copying, +distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the original +licensor to copy, distribute or modify the Program subject to these terms and +conditions. You may not impose any further restrictions on the recipients' +exercise of the rights granted herein. You are not responsible for enforcing +compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), conditions +are imposed on you (whether by court order, agreement or otherwise) that +contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot distribute so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not distribute the Program at all. +For example, if a patent license would not permit royalty-free redistribution +of the Program by all those who receive copies directly or indirectly through +you, then the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply and +the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or +other property right claims or to contest validity of any such claims; this +section has the sole purpose of protecting the integrity of the free software +distribution system, which is implemented by public license practices. Many +people have made generous contributions to the wide range of software +distributed through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing to +distribute software through any other system and a licensee cannot impose +that choice. + +This section is intended to make thoroughly clear what is believed to be a +consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain +countries either by patents or by copyrighted interfaces, the original copyright +holder who places the Program under this License may add an explicit +geographical distribution limitation excluding those countries, so that +distribution is permitted only in or among countries not thus excluded. In such +case, this License incorporates the limitation as if written in the body of this +License. + +9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will be +similar in spirit to the present version, but may differ in detail to address new +problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies +a version number of this License which applies to it and "any later version", +you have the option of following the terms and conditions either of that +version or of any later version published by the Free Software Foundation. If +the Program does not specify a version number of this License, you may +choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs +whose distribution conditions are different, write to the author to ask for +permission. For software which is copyrighted by the Free Software +Foundation, write to the Free Software Foundation; we sometimes make +exceptions for this. Our decision will be guided by the two goals of +preserving the free status of all derivatives of our free software and of +promoting the sharing and reuse of software generally. + + NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT +PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE +STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT +WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND +PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL +NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR +AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR +ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE +LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, +SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA +OR DATA BEING RENDERED INACCURATE OR LOSSES +SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE +PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN +IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF +THE POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/README.txt b/README.txt new file mode 100644 index 00000000..cad2ab58 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +!!! this module is not ready tu use !!! \ No newline at end of file From 930913e7645bdd2b2d66e0484922fb8b0c334383 Mon Sep 17 00:00:00 2001 From: bachy Date: Thu, 29 Sep 2011 20:36:46 +0200 Subject: [PATCH 04/24] term is saved (created) and node tagged with, but then term name will not be updated yet. module can't add term form in the node form yet. Signed-off-by: bachy --- tode.module | 305 +++++++++++++++------------------------------------- 1 file changed, 86 insertions(+), 219 deletions(-) diff --git a/tode.module b/tode.module index 5ff7d1c4..f731dc94 100644 --- a/tode.module +++ b/tode.module @@ -60,7 +60,7 @@ function tode_field_widget_info() { return array( 'tode' => array( - 'label' => t('Create update/change'), + 'label' => t('Tode (create then update one unique term)'), 'field types' => array('taxonomy_term_reference'), 'behaviors' => array( 'multiple values' => FIELD_BEHAVIOR_DEFAULT, @@ -159,7 +159,10 @@ function tode_field_widget_settings_form($field, $instance){ // } function _tode_widget_settings_maxlength_validate($element, &$form_state) { - $value = $form_state['values']['maxlength']; + // dsm('_tode_widget_settings_maxlength_validate'); + // dsm($form_state, '$form_state'); + $widget = $form_state['values']['instance']['widget']; + $value = $widget['settings']['tode']['maxlength']; if (!is_numeric($value) || intval($value) != $value || $value <= 0) { form_error($element, t('"Maximum length" must be a positive integer.')); } @@ -196,9 +199,12 @@ function tode_element_info() { * 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'); + // dsm('tode_field_widget_form'); + // dsm($items, 'items'); + // dsm($element, '$element'); + // dsm($field, '$field'); + // dsm($instance, '$instance'); + /* $element['#entity_type'] $element['#bundle'] @@ -212,30 +218,13 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco $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 = taxonomy_term_load($items[0]['tid']); + dsm($term, '$term'); + $term_name = $term->name; $term_tid = $term->tid; } @@ -250,79 +239,13 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco ); # add the term edit form - // if(isset($value)) - // _tode_add_term_form($element, $term, $widget['show_term_form']); + // if($term_tid) + // _tode_add_term_form($element, $term, $instance['widget']['settings']['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) * @@ -330,42 +253,42 @@ function tode_element_process($element, $edit, $form_state, $form) { 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'); + $term_form = _tode_term_form($term); + dsm($term_form, 'term_form'); if($term_form){ - - $term_form['identification']['#prefix'] = '
'; - $term_form['identification']['#suffix'] = '
'; - $term_form['advanced']['synonyms']['#prefix'] = '
'; - $term_form['advanced']['synonyms']['#suffix'] = '
'; - $term_form['advanced']['weight']['#prefix'] = '
'; - $term_form['advanced']['weight']['#suffix'] = '
'; - $term_form['advanced']['parent']['#prefix'] = '
'; - $term_form['advanced']['parent']['#suffix'] = '
'; - $term_form['advanced']['relations']['#prefix'] = '
'; - $term_form['advanced']['relations']['#suffix'] = '
'; - - # 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']); + // + // $term_form['identification']['#prefix'] = '
'; + // $term_form['identification']['#suffix'] = '
'; + // $term_form['advanced']['synonyms']['#prefix'] = '
'; + // $term_form['advanced']['synonyms']['#suffix'] = '
'; + // $term_form['advanced']['weight']['#prefix'] = '
'; + // $term_form['advanced']['weight']['#suffix'] = '
'; + // $term_form['advanced']['parent']['#prefix'] = '
'; + // $term_form['advanced']['parent']['#suffix'] = '
'; + // $term_form['advanced']['relations']['#prefix'] = '
'; + // $term_form['advanced']['relations']['#suffix'] = '
'; + // + // # 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', @@ -377,10 +300,10 @@ function _tode_add_term_form(&$element, $term, $show){ '#group'=>'additional_settings', ); - if(!$show){ - $element['term_form']['#prefix'] = '
'; - $element['term_form']['#suffix'] = '
'; - } + // if(!$show){ + // $element['term_form']['#prefix'] = '
'; + // $element['term_form']['#suffix'] = '
'; + // } $term_form = _tode_prefix_form($term_form, 'tode_termform_'.$element['#field_name'].'_'); @@ -391,7 +314,7 @@ function _tode_add_term_form(&$element, $term, $show){ // $element['#prefix'] = '
'; // $element['#suffix'] = '
'; - // dsm($element, 'element'); + dsm($element, 'element'); } } @@ -403,14 +326,14 @@ function _tode_add_term_form(&$element, $term, $show){ * 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'); + // 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'); + // dsm($field, 'field'); $vocabularies = array(); foreach ($field['settings']['allowed_values'] as $tree) { @@ -419,11 +342,8 @@ function tode_validate($element, &$form_state){ } } - - - - // See if the term exists in the chosen vocabulary and return the tid; - // otherwise, create a new 'autocreate' term for insert/update. + // See if the term already exists and load the term + // otherwise, create a new 'autocreate' term for insert. if($tid = $element['tode_tid']['#value']){ $term = taxonomy_term_load($tid); }else{ @@ -436,54 +356,13 @@ function tode_validate($element, &$form_state){ ); } - dsm($term, '$term'); + // dsm($term, '$term'); - $value[] = (array)$term; + $value = (array)$term; } - dsm($value, '$value'); + // 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); } /** @@ -495,38 +374,25 @@ function tode_field_widget_error($element, $error, $form, &$form_state) { } /** - * 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 - * + * Implements hook_node_validate(). + * + * use to save the all term form (steel have to be debuged) + * */ -/* - 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) { +function __tode_node_validate($node, $form){ module_load_include('inc', 'taxonomy', 'taxonomy.admin'); - // dsm('tode save'); - // dsm($node, 'tode submit : node'); + dsm('tode_node_validate'); + dsm($node, '&node'); + dsm($form, '&form'); - $tode_fields = _tode_get_tode_fields_def($node->type); + $tode_fields = _tode_get_tode_fields_def($node); + dsm($tode_fields, '$tode_fields'); + # OK + +/* if(!count($tode_fields)) return; @@ -561,6 +427,7 @@ function tode_save($node) { drupal_execute('taxonomy_form_term', $form_state, taxonomy_vocabulary_load($array_term['vid']), $array_term); } + */ } @@ -700,9 +567,9 @@ function _tode_prefix_form($form, $prefix = '', $add = TRUE){ * _tode_term_form($tid) * */ -function _tode_term_form($tid){ +function _tode_term_form($term){ - if ($array_term = (array)taxonomy_get_term($tid)) { + if ($array_term = (array)$term) { $form_state = array(); $term_form = drupal_retrieve_form('taxonomy_form_term', $form_state, taxonomy_vocabulary_load($array_term['vid']), $array_term); @@ -740,18 +607,18 @@ function _tode_trim_options(&$form, $item){ } /** - * + * OK OK OK */ -function _tode_get_tode_fields_def($type){ - // dsm($type, '_tode_get_fields_def'); +function _tode_get_tode_fields_def($node){ + dsm($node, '_tode_get_fields_def'); #get the fields defenition of node type - $type_fields = content_types($type); - // dsm($type_fields, 'type_fields definition'); + $type_fields = field_info_instances('node', $node->type); + dsm($type_fields, 'type_fields definition'); #get the tode node fields $tode_fields = array(); - foreach ($type_fields['fields'] as $field_name => $field) { + foreach ($type_fields as $field_name => $field) { if($field['widget']['type'] == 'tode') $tode_fields[$field_name] = $field; } From 691ecd7d61d2eb78987900e038995a77d3c67578 Mon Sep 17 00:00:00 2001 From: bachy Date: Tue, 4 Oct 2011 11:37:57 +0200 Subject: [PATCH 05/24] add gui icon Signed-off-by: bachy --- icon.png | Bin 0 -> 690 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 icon.png diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ea1a1090acb247d648a63596fa6d6a02fcfb56d1 GIT binary patch literal 690 zcmV;j0!{siP)>&&c1_NL6)oSGvuSq-i`~AMy@Au&W zq|<3xogU-y_@6HH0PL;lvYrB+Qq}v#V&S`nAoZXXw<7A&e?4@O1%bRqy)yuFF_T&V zRw@TV!e^6aW-nDwRAC2vW6$-nZLrA6qjS5IGF|(#KbS8?u$7tH`@Q&;JA% Y04Qla$nB&I5&!@I07*qoM6N<$f-@&KdjJ3c literal 0 HcmV?d00001 From 626ec7eabcabbc32250cd86a076bd08bed13254b Mon Sep 17 00:00:00 2001 From: bachy Date: Sat, 7 Jan 2012 22:59:15 +0100 Subject: [PATCH 06/24] Parent term options Signed-off-by: bachy --- tode.module | 212 ++++++++++++++++++++++++++++------------------------ 1 file changed, 113 insertions(+), 99 deletions(-) diff --git a/tode.module b/tode.module index f731dc94..38d50aaa 100644 --- a/tode.module +++ b/tode.module @@ -1,6 +1,4 @@ array( 'size' => 60, - 'show_term_form'=> 0, + 'show_term_form'=> -1, + 'choose_term_parent'=> -1, '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 */ @@ -105,16 +88,9 @@ function tode_field_widget_settings_form($field, $instance){ $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'), - ); - + // '#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( + $form['maxlength'] = array( '#type' => 'textfield', '#title' => t('Maximum length of term'), '#default_value' => $settings['maxlength'], @@ -122,47 +98,32 @@ function tode_field_widget_settings_form($field, $instance){ '#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 + TODO complete the all flow of this */ - // 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.'), - // ); - // } + // $form['show_term_form'] = array( + // '#type' => 'checkbox', + // '#title' => t('Show taxonomy term edit form ?'), + // '#default_value' => $settings['show_term_form'], + // ); + + $form['choose_term_parent'] = array( + '#type' => 'checkbox', + '#title' => t('Enable taxonomy term parent selection ?'), + '#default_value' => $settings['choose_term_parent'], + ); 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'] = '
'; -// $form['field']['multiple']['#suffix'] = '
'; -// } -// } - function _tode_widget_settings_maxlength_validate($element, &$form_state) { // dsm('_tode_widget_settings_maxlength_validate'); + // dsm($element, '$element'); // dsm($form_state, '$form_state'); $widget = $form_state['values']['instance']['widget']; - $value = $widget['settings']['tode']['maxlength']; + $value = $widget['settings']['maxlength']; if (!is_numeric($value) || intval($value) != $value || $value <= 0) { form_error($element, t('"Maximum length" must be a positive integer.')); } @@ -183,7 +144,8 @@ function _tode_widget_settings_maxlength_validate($element, &$form_state) { * http://drupal.org/node/224333#hook_element_info * */ -#hook_element_info() +#hook_element_info() WHY ?? +/* function tode_element_info() { return array( 'tode' => array( @@ -194,62 +156,84 @@ function tode_element_info() { ), ); } +*/ /** * 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($form, '&$form'); + // dsm($form_state, '&$form_state'); // dsm($items, 'items'); // dsm($element, '$element'); // dsm($field, '$field'); // dsm($instance, '$instance'); - /* - $element['#entity_type'] - $element['#bundle'] - $element['#field_name'] - $element['#language'] - $element['#columns'] - $element['#title'] - $element['#description'] - $element['#required'] - $element['#delta'] - $element['#language'] - */ - - $term_name = ''; - $term_tid = 0; - - if(count($items)){ - $term = taxonomy_term_load($items[0]['tid']); - dsm($term, '$term'); - $term_name = $term->name; - $term_tid = $term->tid; + if(isset($items[$delta])){ + $term = taxonomy_term_load($items[$delta]['tid']); + // dsm($term, '$term'); + $term_parents = taxonomy_get_parents($term->tid); + dsm($term_parents, '$term_parents'); + $term_parent = array_pop($term_parents); } + + $form['tode_tid'] = array('#type' => 'hidden', '#value' => isset($term) ? $term->tid : 0,'#delta' => $element['#delta'],); - $element['tode_tid'] = array('#type' => 'hidden', '#value' => $term_tid,'#delta' => $element['#delta'],); + + // add parent form autocomplete if activated + if($instance['widget']['settings']['choose_term_parent']){ + $vocabularies = array(); + + foreach ($field['settings']['allowed_values'] as $tree) + if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) + $vocabularies[$vocabulary->vid] = $vocabulary; + + $vocabulary = reset($vocabularies); + // dsm($vocabulary, '$vocabulary'); + + $form['tode_vid'] = array('#type' => 'hidden', '#value' => $vocabulary->vid,'#delta' => $element['#delta'],); + + $form['tode_parent_term'] = array( + '#title' => 'Parent ' . $vocabulary->name . ' (optional)', + '#type' => 'textfield', + '#default_value' => isset($term_parent) ? $term_parent->name : '', + '#autocomplete_path' => 'taxonomy/autocomplete' . '/' . $field['field_name'], + '#size' => 60, + '#maxlength' => 1024, + '#element_validate' => array('tode_autocomplete_validate'), + ); + + } + + // set element form item $element += array( '#type' => 'textfield', - '#default_value' => $term_name, + '#default_value' => isset($term) ? $term->name : '', '#size' => $instance['widget']['settings']['size'], '#maxlength' => $instance['widget']['settings']['maxlength'], '#element_validate' => array('tode_validate'), ); + + # add the term edit form // if($term_tid) // _tode_add_term_form($element, $term, $instance['widget']['settings']['show_term_form']); + // dsm($element, '$element'); return $element; } /** * _tode_add_term_form($term) + * + * show the complete taxonomy term form if feature is enabled * */ +# note available yet with 7.x function _tode_add_term_form(&$element, $term, $show){ module_load_include('inc', 'taxonomy', 'taxonomy.admin'); @@ -320,6 +304,31 @@ function _tode_add_term_form(&$element, $term, $show){ } +/** + * Form element validate handler for tode parent term autocomplete element. + */ +function tode_autocomplete_validate($element, &$form_state) { + // dsm('tode_autocomplete_validate'); + // dsm($element, '$element'); + // dsm($form_state, '$form_state'); + + $value = null; + if ($typed_term = $element['#value']) { + // Translate term names into actual terms. + // See if the term exists in the chosen vocabulary and return the tid; + // otherwise, set error. + if ($possibilities = taxonomy_term_load_multiple(array(), array('name' => trim($typed_term), 'vid' => $form_state['values']['tode_vid']))) { + $term = array_pop($possibilities); + $value = (array)$term; + } + else { + form_error($element, t('Parent term can only be an existing term.')); + } + } + // + form_set_value($element, $value, $form_state); +} + /** * Validation function for the tode element * @@ -330,6 +339,10 @@ function tode_validate($element, &$form_state){ // dsm($form_state, 'form_state'); // dsm($element, 'element'); + /* + TODO term translation (entity translate + node title question) + */ + $value = array(); if ($typed_term = $element['#value']) { $field = field_widget_field($element, $form_state); @@ -344,7 +357,7 @@ function tode_validate($element, &$form_state){ // See if the term already exists and load the term // otherwise, create a new 'autocreate' term for insert. - if($tid = $element['tode_tid']['#value']){ + if($tid = $form_state['values']['tode_tid']){ $term = taxonomy_term_load($tid); }else{ $vocabulary = reset($vocabularies); @@ -356,6 +369,13 @@ function tode_validate($element, &$form_state){ ); } + // save the parent term if provided + if($parent_term = $form_state['values']['tode_parent_term']){ + dsm($parent_term, 'tode_parent_term'); + $term->parent = $parent_term['tid']; + taxonomy_term_save($term); + } + // dsm($term, '$term'); $value = (array)$term; @@ -392,7 +412,7 @@ function __tode_node_validate($node, $form){ # OK -/* + /* if(!count($tode_fields)) return; @@ -430,16 +450,15 @@ function __tode_node_validate($node, $form){ */ } - /** * theme_tode * */ -function theme_tode($element) { - return $element['#children']; -} - - +// function theme_tode($element) { +// dsm('theme_tode'); +// dsm($element, '$element'); +// return $element['#children']; +// } /** @@ -461,7 +480,6 @@ function tode_form_alter(&$form, $form_state, $form_id){ } - function _tode_node_delete_form_alter(&$form){ // dsm($form, '_tode_node_delete_form_alter : form'); #get the node @@ -508,7 +526,6 @@ function _tode_node_delete_form_alter(&$form){ } - function tode_delete_submit($form, &$form_state){ $tids = unserialize($form['tode_delete']['#value']); foreach ($tids as $tid) @@ -518,8 +535,6 @@ function tode_delete_submit($form, &$form_state){ drupal_set_message(t('Following Taxonomy terms have been deleted : %terms', array('%terms' => implode(', ', $terms) )), 'status'); } - - /** * HELPERS */ @@ -529,7 +544,6 @@ function tode_delete_submit($form, &$form_state){ // return $prefix.$k; // } - function _tode_clean_form($form){ foreach ($form as $key => $value) { if(strpos($key,'#') !== false){ @@ -613,12 +627,12 @@ function _tode_get_tode_fields_def($node){ dsm($node, '_tode_get_fields_def'); #get the fields defenition of node type - $type_fields = field_info_instances('node', $node->type); + $type_fields = field_info_instances('node'); dsm($type_fields, 'type_fields definition'); #get the tode node fields $tode_fields = array(); - foreach ($type_fields as $field_name => $field) { + foreach ($type_fields[$node->type] as $field_name => $field) { if($field['widget']['type'] == 'tode') $tode_fields[$field_name] = $field; } From 66ff8370390047d88e6b371e9d19cf303e77d8cb Mon Sep 17 00:00:00 2001 From: bachy Date: Tue, 17 Jan 2012 16:14:17 +0100 Subject: [PATCH 07/24] RC Signed-off-by: bachy --- tode.module | 396 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 229 insertions(+), 167 deletions(-) diff --git a/tode.module b/tode.module index 38d50aaa..90db853e 100644 --- a/tode.module +++ b/tode.module @@ -55,7 +55,6 @@ function tode_init() { /** * Implementation of hook_field_widget_info(). */ -# BUG PLUS function tode_field_widget_info() { return array( @@ -79,10 +78,9 @@ function tode_field_widget_info() { /** * 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'); + // dsm($instance, 'tode_field_widget_settings_form : $instance'); + // dsm($field, 'field'); $widget = $instance['widget']; $settings = $widget['settings']; @@ -102,11 +100,11 @@ function tode_field_widget_settings_form($field, $instance){ /* TODO complete the all flow of this */ - // $form['show_term_form'] = array( - // '#type' => 'checkbox', - // '#title' => t('Show taxonomy term edit form ?'), - // '#default_value' => $settings['show_term_form'], - // ); + $form['show_term_form'] = array( + '#type' => 'checkbox', + '#title' => t('Show taxonomy term edit form ?'), + '#default_value' => $settings['show_term_form'], + ); $form['choose_term_parent'] = array( '#type' => 'checkbox', @@ -146,7 +144,7 @@ function _tode_widget_settings_maxlength_validate($element, &$form_state) { */ #hook_element_info() WHY ?? /* -function tode_element_info() { +function tode_element_info(){ return array( 'tode' => array( '#input' => TRUE, @@ -162,7 +160,7 @@ function tode_element_info() { * 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('- - - - tode_field_widget_form'); // dsm($form, '&$form'); // dsm($form_state, '&$form_state'); // dsm($items, 'items'); @@ -170,22 +168,30 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco // dsm($field, '$field'); // dsm($instance, '$instance'); + + $node = $form_state['node']; + // dsm($node, '$node'); + if(isset($items[$delta])){ $term = taxonomy_term_load($items[$delta]['tid']); + // $term = i18n_taxonomy_term_get_translation($term, $node->language); // marche pas avec localized term // dsm($term, '$term'); $term_parents = taxonomy_get_parents($term->tid); - dsm($term_parents, '$term_parents'); + // dsm($term_parents, '$term_parents'); $term_parent = array_pop($term_parents); } + # no need of $node->translation_source because with node translation (not entity fields translation) tid remains + # just have to translate term name on submit + // if( !isset($node->id) && isset($node->translation_source) ){ + // } + $form['tode_tid'] = array('#type' => 'hidden', '#value' => isset($term) ? $term->tid : 0,'#delta' => $element['#delta'],); - - - // add parent form autocomplete if activated - if($instance['widget']['settings']['choose_term_parent']){ - + + # parent + if( $instance['widget']['settings']['choose_term_parent'] ){ + // add parent form autocomplete if activated $vocabularies = array(); - foreach ($field['settings']['allowed_values'] as $tree) if ($vocabulary = taxonomy_vocabulary_machine_name_load($tree['vocabulary'])) $vocabularies[$vocabulary->vid] = $vocabulary; @@ -202,27 +208,33 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco '#autocomplete_path' => 'taxonomy/autocomplete' . '/' . $field['field_name'], '#size' => 60, '#maxlength' => 1024, - '#element_validate' => array('tode_autocomplete_validate'), + '#element_validate' => array('tode_parent_autocomplete_validate'), ); + }else{ + // if parent selection not enabled set the current parent as hidden input + $form['tode_parent_term'] = array( + '#type' => 'hidden', + '#value' => isset($term_parent) ? $term_parent->name : '', + '#delta' => $element['#delta'], + ); } // set element form item $element += array( '#type' => 'textfield', - '#default_value' => isset($term) ? $term->name : '', + '#default_value' => isset($term) ? i18n_taxonomy_term_name($term, $node->language) : '', '#size' => $instance['widget']['settings']['size'], '#maxlength' => $instance['widget']['settings']['maxlength'], '#element_validate' => array('tode_validate'), ); - # add the term edit form - // if($term_tid) - // _tode_add_term_form($element, $term, $instance['widget']['settings']['show_term_form']); + if(isset($term)) + _tode_add_term_form($form, $term, $instance, $element['#delta']); - // dsm($element, '$element'); + // dsm($form, 'end tode_field_widget_form :: $form'); return $element; } @@ -233,72 +245,47 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco * show the complete taxonomy term form if feature is enabled * */ -# note available yet with 7.x -function _tode_add_term_form(&$element, $term, $show){ +function _tode_add_term_form(&$form, $term, $instance, $delta){ + // dsm('- - - - _tode_add_term_form'); module_load_include('inc', 'taxonomy', 'taxonomy.admin'); $term_form = _tode_term_form($term); - dsm($term_form, 'term_form'); + // dsm($term_form, 'term_form'); if($term_form){ - // - // $term_form['identification']['#prefix'] = '
'; - // $term_form['identification']['#suffix'] = '
'; - // $term_form['advanced']['synonyms']['#prefix'] = '
'; - // $term_form['advanced']['synonyms']['#suffix'] = '
'; - // $term_form['advanced']['weight']['#prefix'] = '
'; - // $term_form['advanced']['weight']['#suffix'] = '
'; - // $term_form['advanced']['parent']['#prefix'] = '
'; - // $term_form['advanced']['parent']['#suffix'] = '
'; - // $term_form['advanced']['relations']['#prefix'] = '
'; - // $term_form['advanced']['relations']['#suffix'] = '
'; - // - // # 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( + unset($term_form['actions']); + unset($term_form['#action']); + unset($term_form['#method']); + + #unset vid info 'cause is in conflict with the node's vid field + unset($term_form['vid']); + + $term_form = _tode_clean_form($term_form); + + $prefix = 'tode_termform_'.$instance['field_name']; + $term_form = _tode_prefix_form($term_form, $prefix.'_'); + + $visible = $instance['widget']['settings']['show_term_form']; + + $form[$prefix] = array( '#type' => 'fieldset', '#title' => t('Term edit'), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight'=>1, - '#group'=>'additional_settings', + // '#group'=>'additional_settings', + '#prefix' => $visible ? null : '
', + '#suffix' => $visible ? null : '
', ); - - // if(!$show){ - // $element['term_form']['#prefix'] = '
'; - // $element['term_form']['#suffix'] = '
'; - // } + + $form[$prefix] += $term_form; - $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'],); + // $form['tode_termform'] = array('#type' => 'hidden', '#value' => 'true','#delta' => $delta,); - // $element['#prefix'] = '
'; - // $element['#suffix'] = '
'; - - dsm($element, 'element'); } } @@ -307,12 +294,12 @@ function _tode_add_term_form(&$element, $term, $show){ /** * Form element validate handler for tode parent term autocomplete element. */ -function tode_autocomplete_validate($element, &$form_state) { - // dsm('tode_autocomplete_validate'); +function tode_parent_autocomplete_validate($element, &$form_state) { + // dsm('- - - - tode_autocomplete_validate'); // dsm($element, '$element'); // dsm($form_state, '$form_state'); - $value = null; + $value = array(); if ($typed_term = $element['#value']) { // Translate term names into actual terms. // See if the term exists in the chosen vocabulary and return the tid; @@ -326,6 +313,7 @@ function tode_autocomplete_validate($element, &$form_state) { } } // + // dsm('form_set_value'); form_set_value($element, $value, $form_state); } @@ -335,10 +323,12 @@ function tode_autocomplete_validate($element, &$form_state) { * parses input and sets the values as needed (tid) for storing the data */ function tode_validate($element, &$form_state){ - // dsm('tode_validate'); + // dsm('- - - - tode_validate'); // dsm($form_state, 'form_state'); // dsm($element, 'element'); - + + $node = $form_state['node']; + /* TODO term translation (entity translate + node title question) */ @@ -355,32 +345,33 @@ function tode_validate($element, &$form_state){ } } + // get the parent term tid or 0 (no parents) + $parent_tid = isset($form_state['values']['tode_parent_term']['tid']) ? $form_state['values']['tode_parent_term']['tid'] : 0; + // See if the term already exists and load the term // otherwise, create a new 'autocreate' term for insert. if($tid = $form_state['values']['tode_tid']){ $term = taxonomy_term_load($tid); + + $term->name = $typed_term; + $term->parent = $parent_tid; + }else{ $vocabulary = reset($vocabularies); - $term = array( - 'tid' => 'autocreate', + $term = (object)array( + // 'tid' => 'autocreate', // autocreate not nbeeded with direct taxonomy_term_save 'vid' => $vocabulary->vid, 'name' => $typed_term, 'vocabulary_machine_name' => $vocabulary->machine_name, + 'parent' => $parent_tid, ); - } - - // save the parent term if provided - if($parent_term = $form_state['values']['tode_parent_term']){ - dsm($parent_term, 'tode_parent_term'); - $term->parent = $parent_term['tid']; - taxonomy_term_save($term); + taxonomy_term_save($term); // save here the new term to directly get the tid on hook_node_validate } // dsm($term, '$term'); - $value = (array)$term; - } + // dsm($value, '$value'); form_set_value($element, $value, $form_state); } @@ -399,62 +390,87 @@ function tode_field_widget_error($element, $error, $form, &$form_state) { * use to save the all term form (steel have to be debuged) * */ -function __tode_node_validate($node, $form){ - - module_load_include('inc', 'taxonomy', 'taxonomy.admin'); - - dsm('tode_node_validate'); - dsm($node, '&node'); - dsm($form, '&form'); +function tode_node_validate($node, $form, &$form_state){ + // dsm('- - - tode_node_validate'); + // dsm($node, '$node'); + // dsm($form, '$form'); + // dsm($form_state, '$form_state'); + module_load_include('inc', 'taxonomy', 'taxonomy.admin'); + // module_load_include('inc', 'i18n_string', 'i18n_string.pages'); + // $tode_fields = _tode_get_tode_fields_def($node); - dsm($tode_fields, '$tode_fields'); + // dsm($tode_fields, '$tode_fields'); - # OK - /* if(!count($tode_fields)) return; - + + $language = $node->language; + + $default_language = language_default('language'); + // dsm($default_language, '$default_language'); + 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; + + // retreive the prefixed termfom values (hidden or visible) + $prefix = 'tode_termform_'.$field_name; + + // if we do not have the term form (node creation) + if( !isset($form_state['values'][$prefix]) ){ + $tode_field_term_value = $form_state['values'][$field_name]['und'][0]; // on node creation field language is always to und (sure ?) + + // test the language, if not default language create the term name translation + if( $form_state['values']['language'] != 'und' || $form_state['values']['language'] != $default_language){ + $context= array('term',$tode_field_term_value['tid'],'name'); + i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); + } + + continue; + }else{ + // retreive the initial tode_field language + $init_language = $form[$field_name]['#language']; + + // retreive the value of term field, to get the typed term name + $tode_field_term_value = $form_state['values'][$field_name][$init_language][0]; + // dsm($tode_field_term_value, '$tode_field_term_value'); + + $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); + // dsm($values, 'values'); + + if($language == 'und' || $language == $default_language || !module_exists('i18n_taxonomy')){ + + // define the form_state for term_form submit + $new_term_form_state = array( + 'build_info'=>array( + 'args'=>array(0=>(object)$tode_field_term_value), + ), + "values"=>array( + 'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field + 'op'=> t('Save'), + ) + ); + // add new values to form_state + $new_term_form_state['values'] += $values; + + // dsm($new_term_form_state, 'form_state'); + drupal_form_submit('taxonomy_form_term', $new_term_form_state); + }else{ + + $context= array('term',$values['tid'],'name'); + + i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); + } } - // 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) { +// function theme_tode($element) {1 // dsm('theme_tode'); // dsm($element, '$element'); // return $element['#children']; @@ -469,67 +485,105 @@ function __tode_node_validate($node, $form){ */ function tode_form_alter(&$form, $form_state, $form_id){ + /* + TODO block the deletion if tode term has children !! cause will delete them to … + */ + 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); + }else if(stripos($form_id, 'node_admin_content') !== false){ + if(isset($form['operation']) && $form['operation']['#value'] == 'delete'){ + // dsm($form, 'node_admin_content form'); + // dsm($form_state, 'form_state'); + _tode_nodes_delete_form_alter($form, $form_state); + + } } } -function _tode_node_delete_form_alter(&$form){ +function _tode_node_delete_form_alter(&$form, $form_state){ // 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 node + $node = $form['#node']; + // dsm($node, '$node'); #get the fields defenition of node type - $tode_fields = _tode_get_tode_fields_def($node->type); - //dsm($tode_fields); + $tode_fields = _tode_get_tode_fields_def($node); + // 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; - } + $terms = array('names'=>array(), 'tids'=>array()); + foreach ($tode_fields as $field_name => $field) + _tode_populate_terms_node_delete($terms, $node->$field_name); + + _tode_node_delete_prepare_form($form, $terms); +} + +function _tode_nodes_delete_form_alter(&$form, $form_state){ + // dsm($form, '_tode_nodes_delete_form_alter : form'); + $nodes = array(); + foreach ($form_state['values']['nodes'] as $nid => $actif) + if($actif) + $nodes[] = node_load($nid); + + #get the terms value + $terms = array('names'=>array(), 'tids'=>array()); + foreach ($nodes as $node) { + #get the fields definition of node type + $tode_fields = _tode_get_tode_fields_def($node); + //dsm($tode_fields); + + if(count($tode_fields) == 0) + continue; + + foreach ($tode_fields as $field_name => $field) + _tode_populate_terms_node_delete($terms, $node->$field_name); + } + _tode_node_delete_prepare_form($form, $terms); +} + +function _tode_populate_terms_node_delete(&$terms, $tode_field){ + foreach ($tode_field as $language) { + foreach ($language as $term) { + $term = taxonomy_term_load($term['tid']); + if(!in_array($term->tid, $terms['tids'])){ + $terms['names'][] = $term->name; + $terms['tids'][] = $term->tid; + } + } + } +} + +function _tode_node_delete_prepare_form(&$form, $terms){ if(count($terms)){ /* TODO add here a checkbox to select terms to delete */ #add some warning in form description - $form['description']['#value'] .= '
'.t('this will also delete taxonomy terms : %terms', array('%terms'=>implode(', ', $terms))); + $form['description']['#markup'] .= '
'.t('this will also delete taxonomy terms : %terms', array('%terms'=>implode(', ', $terms['names']))); - $form['tode_delete'] = array( '#type' => 'hidden', '#value' => serialize($tids),); + $form['tode_delete'] = array( '#type' => 'hidden', '#value' => serialize($terms['tids']),); - $form['tode_terms'] = array('#type' => 'hidden', '#value' => serialize($terms),); + $form['tode_terms'] = array('#type' => 'hidden', '#value' => serialize($terms['names']),); $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); + taxonomy_term_delete($tid); $terms = unserialize($form['tode_terms']['#value']); drupal_set_message(t('Following Taxonomy terms have been deleted : %terms', array('%terms' => implode(', ', $terms) )), 'status'); @@ -544,12 +598,13 @@ function tode_delete_submit($form, &$form_state){ // return $prefix.$k; // } -function _tode_clean_form($form){ +function _tode_clean_form($form, $level = 0){ foreach ($form as $key => $value) { - if(strpos($key,'#') !== false){ - unset($form[$key]); + if(strpos($key,'#') !== false || $key == 'form_build_id' || $key == 'form_id' || $key == 'form_token'){ + if( $level == 0 || $key == "#element_validate") + unset($form[$key]); }elseif(is_array($value)){ - $form[$key] = _tode_clean_form($value); + $form[$key] = _tode_clean_form($value, $level+1); } } return $form; @@ -560,7 +615,7 @@ 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))) + if((isset($value['#type']) && $value['#type'] == 'fieldset') || (!$add && is_array($value))) $value = _tode_prefix_form($value, $prefix, $add); if($add){ @@ -582,11 +637,18 @@ function _tode_prefix_form($form, $prefix = '', $add = TRUE){ * */ function _tode_term_form($term){ - - if ($array_term = (array)$term) { + // dsm('_tode_term_form'); + if ($term) { - $form_state = array(); - $term_form = drupal_retrieve_form('taxonomy_form_term', $form_state, taxonomy_vocabulary_load($array_term['vid']), $array_term); + $form_state = array( + 'build_info'=>array( + 'args'=>array(0=>$term) + ), + 'method'=>'post', + ); + + // function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL) { + $term_form = drupal_retrieve_form('taxonomy_form_term', $form_state); drupal_prepare_form('taxonomy_form_term', $term_form, $form_state); return $term_form; @@ -624,11 +686,11 @@ function _tode_trim_options(&$form, $item){ * OK OK OK */ function _tode_get_tode_fields_def($node){ - dsm($node, '_tode_get_fields_def'); + // dsm($node, '_tode_get_fields_def'); #get the fields defenition of node type $type_fields = field_info_instances('node'); - dsm($type_fields, 'type_fields definition'); + // dsm($type_fields, 'type_fields definition'); #get the tode node fields $tode_fields = array(); From 8690f4a165e2a052efd2b2ca523b48807c2fee39 Mon Sep 17 00:00:00 2001 From: bachy Date: Thu, 2 Feb 2012 18:48:13 +0100 Subject: [PATCH 08/24] =?UTF-8?q?c=C3=A0rrectif=20bug=20:=20term=20created?= =?UTF-8?q?=20even=20if=20node=20form=20validation=20fail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remove taxonomy term save from tod, let taxonomy handle the term - move all toed process from hook_node_validate to hook_node_submit - handle node creation with hook_node_presave - handle node update (with term form) in hook_node_submit Signed-off-by: bachy --- tode.module | 165 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 95 insertions(+), 70 deletions(-) diff --git a/tode.module b/tode.module index 90db853e..be454b7e 100644 --- a/tode.module +++ b/tode.module @@ -226,7 +226,8 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco '#default_value' => isset($term) ? i18n_taxonomy_term_name($term, $node->language) : '', '#size' => $instance['widget']['settings']['size'], '#maxlength' => $instance['widget']['settings']['maxlength'], - '#element_validate' => array('tode_validate'), + '#element_validate' => array('tode_widget_validate'), + // '#element_submit' => array('tode_widget_submit'), ); @@ -322,16 +323,13 @@ function tode_parent_autocomplete_validate($element, &$form_state) { * * parses input and sets the values as needed (tid) for storing the data */ -function tode_validate($element, &$form_state){ - // dsm('- - - - tode_validate'); +function tode_widget_validate($element, &$form_state){ + // dsm('- - - - tode_widget_validate'); // dsm($form_state, 'form_state'); // dsm($element, 'element'); $node = $form_state['node']; - /* - TODO term translation (entity translate + node title question) - */ $value = array(); if ($typed_term = $element['#value']) { @@ -359,13 +357,17 @@ function tode_validate($element, &$form_state){ }else{ $vocabulary = reset($vocabularies); $term = (object)array( - // 'tid' => 'autocreate', // autocreate not nbeeded with direct taxonomy_term_save + 'tid' => 'autocreate', // autocreate not needed with direct taxonomy_term_save [EDIT] autocreate needed because of the hook_submit insted of hook_validate 'vid' => $vocabulary->vid, 'name' => $typed_term, 'vocabulary_machine_name' => $vocabulary->machine_name, 'parent' => $parent_tid, ); - taxonomy_term_save($term); // save here the new term to directly get the tid on hook_node_validate + // taxonomy_term_save($term); // save here the new term to directly get the tid on hook_node_validate + // [EDIT] do not save the term here because it will be save even if node form is not validate + // results term without node or mutiple orfan term + // moving all process on node submit + } // dsm($term, '$term'); @@ -376,6 +378,7 @@ function tode_validate($element, &$form_state){ form_set_value($element, $value, $form_state); } + /** * Implements hook_field_widget_error(). */ @@ -384,18 +387,17 @@ function tode_field_widget_error($element, $error, $form, &$form_state) { form_error($element['value'], $error['message']); } + /** - * Implements hook_node_validate(). - * - * use to save the all term form (steel have to be debuged) - * + * Implements hook_node_submit(). */ -function tode_node_validate($node, $form, &$form_state){ - // dsm('- - - tode_node_validate'); - // dsm($node, '$node'); +function tode_node_submit($node, $form, &$form_state) { + // dsm('- - - tode_node_submit'); + // dsm($node, '$node'); // dsm($form, '$form'); // dsm($form_state, '$form_state'); + module_load_include('inc', 'taxonomy', 'taxonomy.admin'); // module_load_include('inc', 'i18n_string', 'i18n_string.pages'); // @@ -416,65 +418,94 @@ function tode_node_validate($node, $form, &$form_state){ // retreive the prefixed termfom values (hidden or visible) $prefix = 'tode_termform_'.$field_name; - // if we do not have the term form (node creation) - if( !isset($form_state['values'][$prefix]) ){ - $tode_field_term_value = $form_state['values'][$field_name]['und'][0]; // on node creation field language is always to und (sure ?) - - // test the language, if not default language create the term name translation - if( $form_state['values']['language'] != 'und' || $form_state['values']['language'] != $default_language){ - $context= array('term',$tode_field_term_value['tid'],'name'); - i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); - } - + // if term_form is not available + // it meens that we are on the creation of a node + // hook_node_presave will handle this case + if( !isset($form_state['values'][$prefix]) ) continue; - }else{ - // retreive the initial tode_field language - $init_language = $form[$field_name]['#language']; + + // else + // we are on the update or on the translation (from initial node) + // so we can go forward + + // retreive the initial tode_field language + $init_language = $form[$field_name]['#language']; + + // retreive the value of term field, to get the typed term name + $tode_field_term_value = $form_state['values'][$field_name][$init_language][0]; + // dsm($tode_field_term_value, '$tode_field_term_value'); - // retreive the value of term field, to get the typed term name - $tode_field_term_value = $form_state['values'][$field_name][$init_language][0]; - // dsm($tode_field_term_value, '$tode_field_term_value'); + $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); + // dsm($values, 'values'); + + if($language == 'und' || $language == $default_language || !module_exists('i18n_taxonomy')){ + + // define the form_state for term_form submit + $new_term_form_state = array( + 'build_info'=>array( + 'args'=>array(0=>(object)$tode_field_term_value), + ), + "values"=>array( + 'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field + 'op'=> t('Save'), + ) + ); + // add new values to form_state + $new_term_form_state['values'] += $values; + + // dsm($new_term_form_state, 'form_state'); + drupal_form_submit('taxonomy_form_term', $new_term_form_state); + }else{ - $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); - // dsm($values, 'values'); + $context= array('term',$values['tid'],'name'); - if($language == 'und' || $language == $default_language || !module_exists('i18n_taxonomy')){ + i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); + } - // define the form_state for term_form submit - $new_term_form_state = array( - 'build_info'=>array( - 'args'=>array(0=>(object)$tode_field_term_value), - ), - "values"=>array( - 'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field - 'op'=> t('Save'), - ) - ); - // add new values to form_state - $new_term_form_state['values'] += $values; - - // dsm($new_term_form_state, 'form_state'); - drupal_form_submit('taxonomy_form_term', $new_term_form_state); - }else{ - - $context= array('term',$values['tid'],'name'); - - i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); - } + } + +} + + + +/** + * Implements hook_node_presave(). + */ +function tode_node_presave($node) { + // dsm('- - - tode_node_presave'); + // dsm($node, 'node'); + + if($node->nid) + return; + + $tode_fields = _tode_get_tode_fields_def($node); + + if(!count($tode_fields)) + return; + + $default_language = language_default('language'); + + // purpose of that is to directly atribute the right language to the term + foreach ($tode_fields as $field_name => $field){ + $tode_field = $node->$field_name; + $tode_field_term = $tode_field[$node->language][0]; // on node creation field language is always to und (sure ?) + + // // test the language, if not default language create the term name translation + if( module_exists('i18n_taxonomy') && ( $node->language != 'und' || $node->language != $default_language ) ){ + $context= array('term',$tode_field_term['tid'],'name'); + i18n_string_textgroup('taxonomy')->update_translation($context, $node->language, $tode_field_term['name']); } } } -/** - * theme_tode - * - */ -// function theme_tode($element) {1 -// dsm('theme_tode'); -// dsm($element, '$element'); -// return $element['#children']; -// } + +/* + TODO Sélectionner une traduction pour test tode fr + merge two terms when translation is made by selecting a node whiche already exists +*/ + + /** @@ -592,12 +623,6 @@ function tode_delete_submit($form, &$form_state){ /** * HELPERS */ -// -// function _tode_prefix_keys($k){ -// if(strpos('#', $kk) == false) -// return $prefix.$k; -// } - function _tode_clean_form($form, $level = 0){ foreach ($form as $key => $value) { if(strpos($key,'#') !== false || $key == 'form_build_id' || $key == 'form_id' || $key == 'form_token'){ From 4fc8e542c31bce168fa1471d3cdd6d61579e4599 Mon Sep 17 00:00:00 2001 From: bachy Date: Sat, 4 Feb 2012 11:47:59 +0100 Subject: [PATCH 09/24] fixed i18n_taxonomy missing added module_exists('i18n_taxonomy') Signed-off-by: bachy --- tode.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tode.module b/tode.module index be454b7e..0ead66fc 100644 --- a/tode.module +++ b/tode.module @@ -223,7 +223,7 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco // set element form item $element += array( '#type' => 'textfield', - '#default_value' => isset($term) ? i18n_taxonomy_term_name($term, $node->language) : '', + '#default_value' => isset($term) ? ( if(module_exists('i18n_taxonomy')) ? i18n_taxonomy_term_name($term, $node->language) : $term->name ) : '', '#size' => $instance['widget']['settings']['size'], '#maxlength' => $instance['widget']['settings']['maxlength'], '#element_validate' => array('tode_widget_validate'), @@ -438,7 +438,7 @@ function tode_node_submit($node, $form, &$form_state) { $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); // dsm($values, 'values'); - if($language == 'und' || $language == $default_language || !module_exists('i18n_taxonomy')){ + if(!module_exists('i18n_taxonomy') || $language == 'und' || $language == $default_language){ // define the form_state for term_form submit $new_term_form_state = array( @@ -517,7 +517,7 @@ function tode_node_presave($node) { function tode_form_alter(&$form, $form_state, $form_id){ /* - TODO block the deletion if tode term has children !! cause will delete them to … + TODO block the deletion if tode term has children !! because this will delete them to … */ if (stripos($form_id, 'node_delete_confirm') !== false){ From fbaa166db8abcb71049ad5de569ae78be9d0da89 Mon Sep 17 00:00:00 2001 From: bachy Date: Sat, 4 Feb 2012 12:29:28 +0100 Subject: [PATCH 10/24] bug correction Signed-off-by: bachy --- tode.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tode.module b/tode.module index 0ead66fc..ffa20d47 100644 --- a/tode.module +++ b/tode.module @@ -223,7 +223,7 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco // set element form item $element += array( '#type' => 'textfield', - '#default_value' => isset($term) ? ( if(module_exists('i18n_taxonomy')) ? i18n_taxonomy_term_name($term, $node->language) : $term->name ) : '', + '#default_value' => isset($term) ? ( module_exists('i18n_taxonomy') ? i18n_taxonomy_term_name($term, $node->language) : $term->name ) : '', '#size' => $instance['widget']['settings']['size'], '#maxlength' => $instance['widget']['settings']['maxlength'], '#element_validate' => array('tode_widget_validate'), From 6ab6fc916b6e30b8ff6698feffe8ca46b9a57afb Mon Sep 17 00:00:00 2001 From: bachy Date: Tue, 7 Feb 2012 19:46:12 +0100 Subject: [PATCH 11/24] views integration start, not sure to keep that Signed-off-by: bachy --- tode.module | 17 +++++++++++ views/tode.views.inc | 33 ++++++++++++++++++++++ views/tode_views_handler_parent_filter.inc | 0 3 files changed, 50 insertions(+) create mode 100644 views/tode.views.inc create mode 100644 views/tode_views_handler_parent_filter.inc diff --git a/tode.module b/tode.module index ffa20d47..943c7540 100644 --- a/tode.module +++ b/tode.module @@ -33,6 +33,21 @@ function tode_menu() { } */ +/** + * Implements hook_views_api(). + */ +/* + TODO hook_views_api(). +*/ +// function tode_views_api() { +// return array( +// 'api' => 3, +// 'path' => drupal_get_path('module', 'tode') . '/views', +// ); +// } + + + /** * Implementation of hook_theme(). */ @@ -727,3 +742,5 @@ function _tode_get_tode_fields_def($node){ return $tode_fields; } + + diff --git a/views/tode.views.inc b/views/tode.views.inc new file mode 100644 index 00000000..bd1a6724 --- /dev/null +++ b/views/tode.views.inc @@ -0,0 +1,33 @@ + t('tode'), +// 'title' => t('Tode'), +// 'help' => t('Filtrer with tode parent term.'), // The help that appears on the UI, +// // 'real field' => 'field_pv_value', +// 'filter' => array( +// 'handler' => 'tode_views_handler_parent_filter', +// ), +// ); +// +// } + +function tode_views_data_alter(&$data) { + $data['tid']['tode_parent'] = array( + 'title' => t('Tode parent'), + 'group' => 'Tode', + 'help' => t('Parent term of tode field'), + 'real field' => 'field_tode_program', + 'filter' => array( + 'handler' => 'tode_views_handler_parent_filter', + ), + ); +} \ No newline at end of file diff --git a/views/tode_views_handler_parent_filter.inc b/views/tode_views_handler_parent_filter.inc new file mode 100644 index 00000000..e69de29b From 9d10e145b4df72cb2889f460e954070535f26446 Mon Sep 17 00:00:00 2001 From: bachy Date: Fri, 10 Feb 2012 19:53:00 +0100 Subject: [PATCH 12/24] micro debug Signed-off-by: bachy --- tode.module | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tode.module b/tode.module index 943c7540..02bcc06b 100644 --- a/tode.module +++ b/tode.module @@ -600,7 +600,7 @@ function _tode_populate_terms_node_delete(&$terms, $tode_field){ foreach ($tode_field as $language) { foreach ($language as $term) { $term = taxonomy_term_load($term['tid']); - if(!in_array($term->tid, $terms['tids'])){ + if(isset($term->tid) && !in_array($term->tid, $terms['tids'])){ $terms['names'][] = $term->name; $terms['tids'][] = $term->tid; } @@ -609,6 +609,7 @@ function _tode_populate_terms_node_delete(&$terms, $tode_field){ } function _tode_node_delete_prepare_form(&$form, $terms){ + if(count($terms)){ /* TODO add here a checkbox to select terms to delete From 20ad82694bd42540fa40e1fbda7ed3bab5045143 Mon Sep 17 00:00:00 2001 From: bachy Date: Tue, 13 Mar 2012 17:24:52 +0100 Subject: [PATCH 13/24] modale Tode creation Signed-off-by: bachy --- tode.css | 31 +++- tode.module | 490 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 458 insertions(+), 63 deletions(-) diff --git a/tode.css b/tode.css index 0d82149b..1f2751d8 100644 --- a/tode.css +++ b/tode.css @@ -1,3 +1,32 @@ .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;} \ No newline at end of file +#node-form fieldset.tcu-term-fields{width:45%; display:inline-block; vertical-align: top;} + +.tode-add-modal-wrapper{ + +} +.tode-add-modal-wrapper .form-item{ + display:inline-block; +} +.tode-add-modal-wrapper .tode-add-modal-links{ + display:inline-block; +} + +#modalContent{ + +} + +#modalContent div.ctools-modal-content{ + padding:5px; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; + + border: 0 solid #999; + +} +#modalContent div.ctools-modal-content .modal-header, +#modalContent div.ctools-modal-content .modal-header a, +#modalContent div.ctools-modal-content .modal-header span{ + background-color: transparent; color:#000!important; +} diff --git a/tode.module b/tode.module index 02bcc06b..891faa4e 100644 --- a/tode.module +++ b/tode.module @@ -11,27 +11,7 @@ * */ -/** - * 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; -} -*/ /** * Implements hook_views_api(). @@ -127,8 +107,19 @@ function tode_field_widget_settings_form($field, $instance){ '#default_value' => $settings['choose_term_parent'], ); + $form['redirect_term_to_node'] = array( + '#type' => 'checkbox', + '#title' => t('Rewrite all term link to theire tode node ?'), + '#default_value' => $settings['redirect_term_to_node'], + ); + + $form['show_create_tode'] = array( + '#type' => 'checkbox', + '#title' => t('Show create "tode" on term fields about this tode\'s vocabulary ?'), + '#default_value' => $settings['show_create_tode'], + ); + return $form; - } function _tode_widget_settings_maxlength_validate($element, &$form_state) { @@ -184,7 +175,11 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco // dsm($instance, '$instance'); - $node = $form_state['node']; + if(isset($form_state['node'])){ + $language = $form_state['node']->language; + }else{ + $language = null; + } // dsm($node, '$node'); if(isset($items[$delta])){ @@ -238,7 +233,7 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco // set element form item $element += array( '#type' => 'textfield', - '#default_value' => isset($term) ? ( module_exists('i18n_taxonomy') ? i18n_taxonomy_term_name($term, $node->language) : $term->name ) : '', + '#default_value' => isset($term) ? ( module_exists('i18n_taxonomy') ? i18n_taxonomy_term_name($term, $language) : $term->name ) : '', '#size' => $instance['widget']['settings']['size'], '#maxlength' => $instance['widget']['settings']['maxlength'], '#element_validate' => array('tode_widget_validate'), @@ -343,7 +338,7 @@ function tode_widget_validate($element, &$form_state){ // dsm($form_state, 'form_state'); // dsm($element, 'element'); - $node = $form_state['node']; + // $node = $form_state['node']; $value = array(); @@ -416,7 +411,7 @@ function tode_node_submit($node, $form, &$form_state) { module_load_include('inc', 'taxonomy', 'taxonomy.admin'); // module_load_include('inc', 'i18n_string', 'i18n_string.pages'); // - $tode_fields = _tode_get_tode_fields_def($node); + $tode_fields = _tode_get_node_tode_fields_def($node); // dsm($tode_fields, '$tode_fields'); @@ -447,34 +442,46 @@ function tode_node_submit($node, $form, &$form_state) { $init_language = $form[$field_name]['#language']; // retreive the value of term field, to get the typed term name - $tode_field_term_value = $form_state['values'][$field_name][$init_language][0]; + if(isset($form_state['values'][$field_name][$init_language][0])){ + $tode_field_term_value = $form_state['values'][$field_name][$init_language][0]; + }else if(isset($form_state['values'][$field_name][$language][0])){ + $tode_field_term_value = $form_state['values'][$field_name][$language][0]; + }else if(isset($form_state['values'][$field_name]['und'][0])){ + $tode_field_term_value = $form_state['values'][$field_name]['und'][0]; + }else{ + drupal_set_message('$form_state[values][$field_name][$language][0] is undefined', 'warning'); + $tode_field_term_value = false; + } + // dsm($tode_field_term_value, '$tode_field_term_value'); - - $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); - // dsm($values, 'values'); - - if(!module_exists('i18n_taxonomy') || $language == 'und' || $language == $default_language){ - - // define the form_state for term_form submit - $new_term_form_state = array( - 'build_info'=>array( - 'args'=>array(0=>(object)$tode_field_term_value), - ), - "values"=>array( - 'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field - 'op'=> t('Save'), - ) - ); - // add new values to form_state - $new_term_form_state['values'] += $values; - - // dsm($new_term_form_state, 'form_state'); - drupal_form_submit('taxonomy_form_term', $new_term_form_state); - }else{ - - $context= array('term',$values['tid'],'name'); - - i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); + if($tode_field_term_value){ + $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); + // dsm($values, 'values'); + + if(!module_exists('i18n_taxonomy') || $language == 'und' || $language == $default_language){ + + // define the form_state for term_form submit + $new_term_form_state = array( + 'build_info'=>array( + 'args'=>array(0=>(object)$tode_field_term_value), + ), + "values"=>array( + 'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field + 'op'=> t('Save'), + ) + ); + // add new values to form_state + $new_term_form_state['values'] += $values; + + // dsm($new_term_form_state, 'form_state'); + drupal_form_submit('taxonomy_form_term', $new_term_form_state); + }else{ + + $context= array('term',$values['tid'],'name'); + + i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); + } + } } @@ -493,7 +500,7 @@ function tode_node_presave($node) { if($node->nid) return; - $tode_fields = _tode_get_tode_fields_def($node); + $tode_fields = _tode_get_node_tode_fields_def($node); if(!count($tode_fields)) return; @@ -516,10 +523,307 @@ function tode_node_presave($node) { /* - TODO Sélectionner une traduction pour test tode fr - merge two terms when translation is made by selecting a node whiche already exists + TODO merge two terms when translation is made by selecting a node whiche already exists */ +/* + TODO create a node when a term is created else where than the node which got the tode +*/ + +/** + * Implements hook_menu(). + */ +function tode_menu() { + // dsm('tode_menu'); + $items = array(); + + $items['tode/%ctools_js/add'] = array( + 'title' => 'Tode modal add entity', + 'page callback' => 'tode_entity_add', + 'page arguments' => array(1,3,4,5), + 'access callback' => TRUE, + 'type' => MENU_CALLBACK, + ); + + return $items; +} + +function tode_entity_add($js = FALSE, $bundle, $entity, $title = 'Title'){ + + // Fall back if $js is not set. + if (!$js) { + return drupal_get_form('tode_entity_add_form', $bundle, $entity); + } + + ctools_include('modal'); + ctools_include('ajax'); + $form_state = array( + 'title' => t('Create '.$entity), + 'ajax' => TRUE, + 'build_info' => array('args' => array('0' => $bundle, '1' => $entity, '2' => $title)), + ); + $output = ctools_modal_form_wrapper('tode_entity_add_form', $form_state); + + if (!empty($form_state['executed'])) { + $commands = array(); + $commands[] = ctools_modal_command_dismiss(); + print ajax_render($commands); + exit; + } + else { + print ajax_render($output); + exit; + } + + +} + +function tode_entity_add_form($form, $form_state, $bundle, $entity, $title) { + + $form = array(); + $form['title'] = array( + '#type' => 'textfield', + '#title' => t($title), + '#size' => 40, + '#maxlength' => 255, + ); + $form['bundle'] = array( + '#type' => 'hidden', + '#value' => $bundle, + ); + $form['entity'] = array( + '#type' => 'hidden', + '#value' => $entity, + ); + + $form['create'] = array( + '#type' => 'submit', + '#value' => t('Create'), + ); + + return $form; +} + +function tode_entity_add_form_validate($form, &$form_state){ + + if(empty($form_state['values']['title'])){ + form_set_error('title', 'Title field can\'t be empty!'); + } + +} + +function tode_entity_add_form_submit($form, &$form_state){ + global $user; + // dsm($form_state, '$form_state'); + $values = $form_state['values']; + $bundle_fields = field_info_instances($values['bundle']); + // dsm($bundle_fields, '$bundle_fields'); + + $fields = $bundle_fields[$values['entity']]; + // dsm($fields, '$fields'); + + foreach ($fields as $field_name => $field) { + if($field['widget']['type'] == 'tode'){ + $tode_field = $field; + break; + } + } + + # get vocabulary + $tode_field_infos = field_info_field($field['field_name']); + // dsm($tode_field_infos, '$tode_field_infos'); + $voc_name = $tode_field_infos['settings']['allowed_values'][0]['vocabulary']; + $vocabulary = taxonomy_vocabulary_machine_name_load($voc_name); + // dsm($vocabulary, '$vocabulary'); + + # create the term + $term = new stdClass(); + $term->name = $values['title']; + $term->vid = $vocabulary->vid; // ‘1’ is a vocabulary id you wish this term to assign to + // $term->field_custom_field_name[LANGUAGE_NONE][0]['value'] = ‘Some value’; // OPTIONAL. If your term has a custom field attached it can added as simple as this + taxonomy_term_save($term); // Finally, save our term + // dsm($term, '$term'); + + # create the node + //http://www.group42.ca/creating_and_updating_nodes_programmatically_in_drupal_7 + //http://timonweb.com/how-programmatically-create-nodes-comments-and-taxonomies-drupal-7 + $node = new stdClass(); + $node->type = $values['entity']; + node_object_prepare($node); + $tode_field_name = $tode_field['field_name']; + $node = (array)$node +array( + "title" => $values['title'], + "language" => LANGUAGE_NONE, + "uid" => $user->uid, + $tode_field_name => array( LANGUAGE_NONE => array(0 => array('tid' => $term->tid))), + ); + + +// $node->$tode_field_name[$node->language]['tid'] = $term->tid; + // $node->$tode_field_name = array( $node->language => array('tid' => $term->tid)); + + // $tode_field_name = $tode_field['field_name']; + // $node = (object) array( + // "type" => $values['entity'], + // // node_object_prepare($node); + // "title" => $values['title'], + // "language" => LANGUAGE_NONE, + // "uid" => $user->uid, + // $tode_field_name => array( LANGUAGE_NONE=>array('tid' => $term->tid)), + // ); + $node = (object)$node; + + // dsm($node, '$node'); + node_save($node); + // dsm($node, '$node'); + + + # tag the node with the term + + # set the tode field to the term tid + + +} + + + +function _tode_entity_add_form($js = FALSE, $bundle, $entity) { + // dsm('- - - - tode_entity_add_form'); + // dsm($bundle, '$bundle'); + // dsm($entity, '$entity'); + + // error_log($js); + // error_log($bundle); + // error_log($entity); + // + + global $user; + + //module_load_include('inc', 'node', 'node.pages'); + ctools_include('node.pages', 'node', ''); + + $node = (object) array( + 'uid' => $user->uid, + 'name' => (isset($user->name) ? $user->name : ''), + 'type' => $entity, + 'language' => LANGUAGE_NONE + ); + + $form_id = $entity.'_node_form'; + + if (!$js) { + return drupal_get_form($form_id, $node); + } + + ctools_include('modal'); + ctools_include('ajax'); + + $form_state = array( + 'title' => t('Add '.$entity), + 'ajax' => TRUE, + ); + + $form_state['build_info']['args'] = array($node); + + $output = ctools_modal_form_wrapper($entity.'_node_form', $form_state); + + if (!empty($form_state['executed'])) { + $output = array(); + $output[] = ctools_modal_command_display( t('Node created'), ''); /** Add success message*/ + }; + + print ajax_render($output); + exit; +} + + + +/** + * Implements hook_field_widget_form_alter(). + */ +function tode_field_widget_form_alter(&$element, &$form_state, $context) { + $field = $context['field']; + $instance = $context['instance']; + if($field['type'] == 'taxonomy_term_reference' && $instance['widget']['type'] == 'taxonomy_autocomplete'){ + // dsm('- - - - - tode_field_widget_form_alter'); + // dsm($element, '$element'); + // dsm($form_state, '$form_state'); + // dsm($context, '$context'); + foreach ($field['settings']['allowed_values'] as $key => $value) { + + if($tode = _tode_get_voc_tode_fields_def($value['vocabulary'])){ + + ctools_include('ajax'); + ctools_include('modal'); + ctools_modal_add_js(); + + // ctools_add_css('tode', 'tode'); + // drupal_add_css(drupal_get_path('module', 'tode') . "tode.css"); + // dsm($tode, '$tode'); + $type_fields = field_info_instances('node'); + + + if(!isset($element['#attributes']["class"])) + $element['#attributes']["class"] = array(); + + $element['#attributes']["class"][] = "tode-add-modal"; + + $element['#suffix'] = ''; + foreach ($tode['bundles'] as $bundle => $entities) { + foreach ($entities as $entity) { + $tode_instance = $type_fields[$entity][$tode['field_name']]; + + $btn = ctools_modal_text_button(t('create a new %s', array('%s'=>$entity)), 'tode/nojs/add/'.$bundle.'/'.$entity.'/'.$tode_instance['label'], t('alt'), "ctools-modal-tode-add-modal") . "\n"; // modal-popup-small + // $btn .= ctools_modal_text_button(t('create new test'), 'tode/nojs/add/node/test', t('alt')); + // dsm($btn); + if($element['#suffix'] == '') + $element['#suffix'] = ''; + } + + + } +} + +/** + * Implements hook_taxonomy_term_insert(). + */ +// function tode_taxonomy_term_insert($term) { +// dsm($term, '$term'); +// } @@ -530,11 +834,13 @@ function tode_node_presave($node) { * */ function tode_form_alter(&$form, $form_state, $form_id){ - + // dsm($form_id, 'tode form_alter form_id'); /* TODO block the deletion if tode term has children !! because this will delete them to … */ - + if($form_id == 'test_node_form'){ + // dsm($form_state); + } if (stripos($form_id, 'node_delete_confirm') !== false){ // dsm($form_id, 'tode form_alter form_id'); _tode_node_delete_form_alter($form, $form_state); @@ -557,7 +863,7 @@ function _tode_node_delete_form_alter(&$form, $form_state){ // dsm($node, '$node'); #get the fields defenition of node type - $tode_fields = _tode_get_tode_fields_def($node); + $tode_fields = _tode_get_node_tode_fields_def($node); // dsm($tode_fields); if(count($tode_fields) == 0) @@ -582,7 +888,7 @@ function _tode_nodes_delete_form_alter(&$form, $form_state){ $terms = array('names'=>array(), 'tids'=>array()); foreach ($nodes as $node) { #get the fields definition of node type - $tode_fields = _tode_get_tode_fields_def($node); + $tode_fields = _tode_get_node_tode_fields_def($node); //dsm($tode_fields); if(count($tode_fields) == 0) @@ -636,6 +942,48 @@ function tode_delete_submit($form, &$form_state){ drupal_set_message(t('Following Taxonomy terms have been deleted : %terms', array('%terms' => implode(', ', $terms) )), 'status'); } + +/** + * Implements hook_url_outbound_alter(). + */ +function tode_url_outbound_alter(&$path, &$options, $original_path) { + // dsm($path); + # terms url + if (preg_match('/^taxonomy\/term\/([0-9]*)$/', $path, $matches)) { + $term = taxonomy_term_load($matches[1]); + // dsm($term, '$term'); + $vocabulary = taxonomy_vocabulary_load($term->vid); + // dsm($vocabulary, '$vocabulary'); + + if($field = _tode_get_voc_tode_fields_def($vocabulary->machine_name)){ + // dsm($field, '$field'); + // $existing_item = db_query('SELECT * FROM {menu_links} WHERE mlid = :mlid', array('mlid' => $item['mlid']))->fetchAssoc(); + $sr = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT']; + foreach ($sr as $table => $column) { + $query = db_select($table, 'ft') + ->fields('ft') + ->condition('ft.'.$column['tid'], $term->tid); + + $result = $query->execute(); + + // $entity = db_query('SELECT * FROM :fieldtabe WHERE :fieldcolumn = %tid', array(':fieldtabe'=>$table, ':fieldcolumn'=>$column['tid'], '%tid'=>$term->tid))->fetchAssoc(); + break; + } + // dsm($result, '$result'); + foreach ($result as $entity) { + // dsm($entity, '$entity'); + $path = 'node/'.$entity->entity_id; + break; + } + + } + + } +} + + + + /** * HELPERS */ @@ -724,9 +1072,9 @@ function _tode_trim_options(&$form, $item){ } /** - * OK OK OK + * _tode_get_node_tode_fields_def */ -function _tode_get_tode_fields_def($node){ +function _tode_get_node_tode_fields_def($node){ // dsm($node, '_tode_get_fields_def'); #get the fields defenition of node type @@ -744,4 +1092,22 @@ function _tode_get_tode_fields_def($node){ return $tode_fields; } - +function _tode_get_voc_tode_fields_def($voc_name){ + $type_fields = field_info_instances('node'); + // dsm($type_fields, '$type_fields'); + foreach ($type_fields as $nodetype => $fields) + foreach ($fields as $field_name => $field) + if($field['widget']['type'] == 'tode' + && isset($field['widget']['settings']['redirect_term_to_node']) + && $field['widget']['settings']['redirect_term_to_node'] + ){ + $fieldinfos = field_info_field($field_name); + // dsm($fieldinfos, '$fieldinfos'); + if($voc_name == $fieldinfos['settings']['allowed_values'][0]['vocabulary']) + return $fieldinfos; + } + + + return false; + +} From 9d97a0b7b78d4dbc888439bd5b27c8c6bf7c9e09 Mon Sep 17 00:00:00 2001 From: bachy Date: Sun, 18 Mar 2012 14:38:35 +0100 Subject: [PATCH 14/24] tode_url_outbound_alter improvement (path_alias) Signed-off-by: bachy --- tode.css | 19 ------------ tode.module | 83 ++++++++++++++++++++++++++--------------------------- 2 files changed, 41 insertions(+), 61 deletions(-) diff --git a/tode.css b/tode.css index 1f2751d8..933a4cc3 100644 --- a/tode.css +++ b/tode.css @@ -11,22 +11,3 @@ .tode-add-modal-wrapper .tode-add-modal-links{ display:inline-block; } - -#modalContent{ - -} - -#modalContent div.ctools-modal-content{ - padding:5px; - -moz-border-radius: 10px; - -webkit-border-radius: 10px; - border-radius: 10px; - - border: 0 solid #999; - -} -#modalContent div.ctools-modal-content .modal-header, -#modalContent div.ctools-modal-content .modal-header a, -#modalContent div.ctools-modal-content .modal-header span{ - background-color: transparent; color:#000!important; -} diff --git a/tode.module b/tode.module index 891faa4e..f50d72d4 100644 --- a/tode.module +++ b/tode.module @@ -687,7 +687,7 @@ function tode_entity_add_form_submit($form, &$form_state){ -function _tode_entity_add_form($js = FALSE, $bundle, $entity) { +function BAD_ONE_tode_entity_add_form($js = FALSE, $bundle, $entity) { // dsm('- - - - tode_entity_add_form'); // dsm($bundle, '$bundle'); // dsm($entity, '$entity'); @@ -773,7 +773,7 @@ function tode_field_widget_form_alter(&$element, &$form_state, $context) { foreach ($entities as $entity) { $tode_instance = $type_fields[$entity][$tode['field_name']]; - $btn = ctools_modal_text_button(t('create a new %s', array('%s'=>$entity)), 'tode/nojs/add/'.$bundle.'/'.$entity.'/'.$tode_instance['label'], t('alt'), "ctools-modal-tode-add-modal") . "\n"; // modal-popup-small + $btn = ctools_modal_text_button(t('create a new %s', array('%s'=>$entity)), 'tode/nojs/add/'.$bundle.'/'.$entity.'/'.$tode_instance['label'], t('alt'), "button ctools-modal-tode-add-modal") . "\n"; // modal-popup-small // $btn .= ctools_modal_text_button(t('create new test'), 'tode/nojs/add/node/test', t('alt')); // dsm($btn); if($element['#suffix'] == '') @@ -789,26 +789,24 @@ function tode_field_widget_form_alter(&$element, &$form_state, $context) { $throbber = theme('image', array('path' => ctools_image_path('loading_animation.gif', 'modal_forms'), 'alt' => t('Loading...'), 'title' => t('Loading'))); $js_settings = array( - 'tode-add-modal' => array( - 'modalSize' => array( - 'type' => 'fixed', - 'width' => 500, - 'height' => 200, - ), - 'modalOptions' => array( - 'opacity' => 0.4, - 'background' => '#000', - ), - 'animation' => 'fadeIn', - // 'modalTheme' => 'ModalFormsPopup', - 'throbber' => $throbber, - 'closeText' => t('Close'), - ), - ); - - drupal_add_js($js_settings, 'setting'); - + 'tode-add-modal' => array( + 'modalSize' => array( + 'type' => 'fixed', + 'width' => 500, + 'height' => 200, + ), + 'modalOptions' => array( + 'opacity' => 0.4, + 'background' => '#000', + ), + 'animation' => 'fadeIn', + // 'modalTheme' => 'ModalFormsPopup', + 'throbber' => $throbber, + 'closeText' => t('Close'), + ), + ); + drupal_add_js($js_settings, 'setting'); $element['#prefix'] = '
'; $element['#suffix'] .= '
'; @@ -947,43 +945,44 @@ function tode_delete_submit($form, &$form_state){ * Implements hook_url_outbound_alter(). */ function tode_url_outbound_alter(&$path, &$options, $original_path) { - // dsm($path); # terms url - if (preg_match('/^taxonomy\/term\/([0-9]*)$/', $path, $matches)) { - $term = taxonomy_term_load($matches[1]); - // dsm($term, '$term'); - $vocabulary = taxonomy_vocabulary_load($term->vid); - // dsm($vocabulary, '$vocabulary'); + if(isset($options['entity_type']) && $options['entity_type'] == 'taxonomy_term'){ + // dsm('- - - - tode_url_outbound_alter'); + // dsm($path, '$path'); + // dsm($options, '$options'); + // dsm($original_path, '$original_path'); - if($field = _tode_get_voc_tode_fields_def($vocabulary->machine_name)){ - // dsm($field, '$field'); - // $existing_item = db_query('SELECT * FROM {menu_links} WHERE mlid = :mlid', array('mlid' => $item['mlid']))->fetchAssoc(); + $term = $options['entity']; + + if($field = _tode_get_voc_tode_fields_def($term->vocabulary_machine_name)){ + $sr = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT']; foreach ($sr as $table => $column) { - $query = db_select($table, 'ft') + $query = db_select($table, 'ft'); + $query->join('node', 'n', 'ft.entity_id = n.nid AND n.language = :language', array(':language' => $options['language']->language)); + $query ->fields('ft') ->condition('ft.'.$column['tid'], $term->tid); - $result = $query->execute(); - - // $entity = db_query('SELECT * FROM :fieldtabe WHERE :fieldcolumn = %tid', array(':fieldtabe'=>$table, ':fieldcolumn'=>$column['tid'], '%tid'=>$term->tid))->fetchAssoc(); break; } - // dsm($result, '$result'); - foreach ($result as $entity) { - // dsm($entity, '$entity'); - $path = 'node/'.$entity->entity_id; + + foreach ($result as $node) { + $new_path = 'node/'.$node->entity_id; + if( $new_alias = drupal_get_path_alias($new_path, $options['language']->language) ){ + $path = $new_alias; + $original_path = $new_path; + $options['alias'] = TRUE; + }else{ + $path = $new_path; + } break; } } - } } - - - /** * HELPERS */ From 4a958da4df62d86d291487022a47d3d00bd9bdeb Mon Sep 17 00:00:00 2001 From: bachy Date: Mon, 16 Apr 2012 23:07:27 +0200 Subject: [PATCH 15/24] parent bug on node update fixed parent selection used to works only on node creation, now works on node creation and update add automatic node titles snippet fro term translation Signed-off-by: bachy --- tode.module | 73 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/tode.module b/tode.module index f50d72d4..c9e8a94e 100644 --- a/tode.module +++ b/tode.module @@ -8,6 +8,12 @@ * 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 * + * + * * */ @@ -455,32 +461,43 @@ function tode_node_submit($node, $form, &$form_state) { // dsm($tode_field_term_value, '$tode_field_term_value'); if($tode_field_term_value){ + // dsm($form_state['values'][$prefix], '$form_state["values"][$prefix]'); $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); // dsm($values, 'values'); - if(!module_exists('i18n_taxonomy') || $language == 'und' || $language == $default_language){ - - // define the form_state for term_form submit - $new_term_form_state = array( - 'build_info'=>array( - 'args'=>array(0=>(object)$tode_field_term_value), - ), - "values"=>array( - 'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field - 'op'=> t('Save'), - ) - ); - // add new values to form_state - $new_term_form_state['values'] += $values; - - // dsm($new_term_form_state, 'form_state'); - drupal_form_submit('taxonomy_form_term', $new_term_form_state); - }else{ - + if(module_exists('i18n_taxonomy') && $language != 'und' && $language != $default_language){ $context= array('term',$values['tid'],'name'); i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); + + $tode_field_term_value['name'] = $values['name']; } + + + $parent_tid = $tode_field_term_value['parent']; + $values['parent'] = array($parent_tid => $parent_tid); + + + + // if(!module_exists('i18n_taxonomy') || $language == 'und' || $language == $default_language){ + + // define the form_state for term_form submit + $new_term_form_state = array( + 'build_info'=>array( + 'args'=>array(0=>(object)$tode_field_term_value), + ), + "values"=>array( + 'name'=> $tode_field_term_value['name'], // replace the original (hidden) term name value by the typed in the the entity field + 'op'=> t('Save'), + ) + ); + // add new values to form_state + $new_term_form_state['values'] += $values; + + // dsm($new_term_form_state, 'form_state'); + drupal_form_submit('taxonomy_form_term', $new_term_form_state); + // }else{ + } @@ -740,15 +757,20 @@ function BAD_ONE_tode_entity_add_form($js = FALSE, $bundle, $entity) { /** * Implements hook_field_widget_form_alter(). + * + * add create entity bundle front of term reference field with tode voc */ -function tode_field_widget_form_alter(&$element, &$form_state, $context) { +function DESACTIVATED_tode_field_widget_form_alter(&$element, &$form_state, $context) { $field = $context['field']; $instance = $context['instance']; - if($field['type'] == 'taxonomy_term_reference' && $instance['widget']['type'] == 'taxonomy_autocomplete'){ - // dsm('- - - - - tode_field_widget_form_alter'); - // dsm($element, '$element'); - // dsm($form_state, '$form_state'); - // dsm($context, '$context'); + + if($field['type'] == 'taxonomy_term_reference' && ($instance['widget']['type'] == 'taxonomy_autocomplete' || $instance['widget']['type'] == 'autocomplete_deluxe_taxonomy')){ +// dsm('- - - - - tode_field_widget_form_alter'); + // dsm($element, '$element'); + // dsm($form_state, '$form_state'); + // dsm($context, '$context'); + // dsm($instance['widget']['type'], '$instance[widget][type]'); + foreach ($field['settings']['allowed_values'] as $key => $value) { if($tode = _tode_get_voc_tode_fields_def($value['vocabulary'])){ @@ -812,6 +834,7 @@ function tode_field_widget_form_alter(&$element, &$form_state, $context) { $element['#suffix'] .= ''; } + // dsm($element, '$element'); } } From 4eda04b2f03c91a43ea7c773cb99164576ed5a16 Mon Sep 17 00:00:00 2001 From: bachy Date: Sun, 6 May 2012 22:50:02 +0200 Subject: [PATCH 16/24] improvement Signed-off-by: bachy --- tode.module | 101 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 32 deletions(-) diff --git a/tode.module b/tode.module index c9e8a94e..aeda61f3 100644 --- a/tode.module +++ b/tode.module @@ -218,7 +218,7 @@ function tode_field_widget_form(&$form, &$form_state, $field, $instance, $langco $form['tode_vid'] = array('#type' => 'hidden', '#value' => $vocabulary->vid,'#delta' => $element['#delta'],); $form['tode_parent_term'] = array( - '#title' => 'Parent ' . $vocabulary->name . ' (optional)', + '#title' => 'Parent ' . $vocabulary->name, '#type' => 'textfield', '#default_value' => isset($term_parent) ? $term_parent->name : '', '#autocomplete_path' => 'taxonomy/autocomplete' . '/' . $field['field_name'], @@ -968,7 +968,9 @@ function tode_delete_submit($form, &$form_state){ * Implements hook_url_outbound_alter(). */ function tode_url_outbound_alter(&$path, &$options, $original_path) { + # terms url + $term = false; if(isset($options['entity_type']) && $options['entity_type'] == 'taxonomy_term'){ // dsm('- - - - tode_url_outbound_alter'); // dsm($path, '$path'); @@ -977,33 +979,50 @@ function tode_url_outbound_alter(&$path, &$options, $original_path) { $term = $options['entity']; - if($field = _tode_get_voc_tode_fields_def($term->vocabulary_machine_name)){ - - $sr = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT']; - foreach ($sr as $table => $column) { - $query = db_select($table, 'ft'); - $query->join('node', 'n', 'ft.entity_id = n.nid AND n.language = :language', array(':language' => $options['language']->language)); - $query - ->fields('ft') - ->condition('ft.'.$column['tid'], $term->tid); - $result = $query->execute(); - break; - } - - foreach ($result as $node) { - $new_path = 'node/'.$node->entity_id; - if( $new_alias = drupal_get_path_alias($new_path, $options['language']->language) ){ - $path = $new_alias; - $original_path = $new_path; - $options['alias'] = TRUE; - }else{ - $path = $new_path; - } - break; - } - + }else{ + $args = explode('/', $original_path); + // dsm($args, 'args'); + if($args[0] == 'taxonomy' && $args[1] == 'term' && is_numeric($args[2]) ){ + $term = taxonomy_term_load($args[2]); } - } + + } + + if($term){ + // dsm($term, '$term'); + if($field = _tode_get_voc_tode_fields_def($term->vocabulary_machine_name)){ + # add if widget setting; + if (isset($field['widget']['settings']['redirect_term_to_node']) && $field['widget']['settings']['redirect_term_to_node']) { + // dsm($field, '$field'); + // dsm($options, '$options'); + $sr = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT']; + foreach ($sr as $table => $column) { + $query = db_select($table, 'ft'); + $query->join('node', 'n', 'ft.entity_id = n.nid AND n.language = :language OR n.language = :language', array(':language' => $options['language']->language, ':language' => 'und')); + $query + ->fields('ft') + ->condition('ft.'.$column['tid'], $term->tid); + $result = $query->execute(); + break; + } + + foreach ($result as $node) { + // dsm($node, '$node'); + $new_path = 'node/'.$node->entity_id; + if( $new_alias = drupal_get_path_alias($new_path, $options['language']->language) ){ + $path = $new_alias; + $original_path = $new_path; + $options['alias'] = TRUE; + }else{ + $path = $new_path; + } + break; + } + } + + } + + } } /** @@ -1119,12 +1138,8 @@ function _tode_get_voc_tode_fields_def($voc_name){ // dsm($type_fields, '$type_fields'); foreach ($type_fields as $nodetype => $fields) foreach ($fields as $field_name => $field) - if($field['widget']['type'] == 'tode' - && isset($field['widget']['settings']['redirect_term_to_node']) - && $field['widget']['settings']['redirect_term_to_node'] - ){ + if($field['widget']['type'] == 'tode'){ $fieldinfos = field_info_field($field_name); - // dsm($fieldinfos, '$fieldinfos'); if($voc_name == $fieldinfos['settings']['allowed_values'][0]['vocabulary']) return $fieldinfos; } @@ -1133,3 +1148,25 @@ function _tode_get_voc_tode_fields_def($voc_name){ return false; } + +function tode_get_nids_from_term($term, $language = false){ + $todefield = _tode_get_voc_tode_fields_def($term->vocabulary_machine_name); + + if($todefield){ + $query = new EntityFieldQuery(); + $query->entityCondition('entity_type', 'node') + ->fieldCondition($todefield['field_name'], 'tid', $term->tid); + + if($language) + $query->propertyCondition('language', array('und', $language), 'IN'); + + $result = $query->execute(); + if(count($result)) + return $result; + } + + return false; +} + + + From 93b353922e1399438c98df2131b9fdcfe205b1a6 Mon Sep 17 00:00:00 2001 From: bachy Date: Wed, 9 May 2012 08:13:15 +0200 Subject: [PATCH 17/24] =?UTF-8?q?widget=20settings=20d=C3=A9faut=20values?= =?UTF-8?q?=20fixe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: bachy --- tode.module | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tode.module b/tode.module index aeda61f3..552a368e 100644 --- a/tode.module +++ b/tode.module @@ -71,6 +71,8 @@ function tode_field_widget_info() { 'show_term_form'=> -1, 'choose_term_parent'=> -1, 'maxlength'=> 255, + 'redirect_term_to_node' => -1, + 'show_create_tode' => -1, ), ), ); From 7ce8d94ed9c372efc8213be7a090a8aedb23a8d5 Mon Sep 17 00:00:00 2001 From: bachy Date: Mon, 21 May 2012 17:46:20 +0200 Subject: [PATCH 18/24] php notice fixing Signed-off-by: bachy --- tode.module | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tode.module b/tode.module index 552a368e..a12617db 100644 --- a/tode.module +++ b/tode.module @@ -516,7 +516,7 @@ function tode_node_presave($node) { // dsm('- - - tode_node_presave'); // dsm($node, 'node'); - if($node->nid) + if(isset($node->nid)) return; $tode_fields = _tode_get_node_tode_fields_def($node); @@ -529,6 +529,10 @@ function tode_node_presave($node) { // purpose of that is to directly atribute the right language to the term foreach ($tode_fields as $field_name => $field){ $tode_field = $node->$field_name; + + if(!isset($tode_field[$node->language][0])) + continue; + $tode_field_term = $tode_field[$node->language][0]; // on node creation field language is always to und (sure ?) // // test the language, if not default language create the term name translation From 35a5eb3a60fb9054cebe8eb5f337c1e1c654e997 Mon Sep 17 00:00:00 2001 From: bachy Date: Tue, 22 May 2012 22:40:31 +0200 Subject: [PATCH 19/24] bug fixing tode_url_outbound_alter Signed-off-by: bachy --- tode.module | 63 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/tode.module b/tode.module index a12617db..647db1ad 100644 --- a/tode.module +++ b/tode.module @@ -779,7 +779,7 @@ function DESACTIVATED_tode_field_widget_form_alter(&$element, &$form_state, $con foreach ($field['settings']['allowed_values'] as $key => $value) { - if($tode = _tode_get_voc_tode_fields_def($value['vocabulary'])){ + if($tode = _tode_get_voc_tode_field_def($value['vocabulary'])){ ctools_include('ajax'); ctools_include('modal'); @@ -974,34 +974,41 @@ function tode_delete_submit($form, &$form_state){ * Implements hook_url_outbound_alter(). */ function tode_url_outbound_alter(&$path, &$options, $original_path) { - + // dsm('tode_url_outbound_alter'); # terms url $term = false; - if(isset($options['entity_type']) && $options['entity_type'] == 'taxonomy_term'){ - // dsm('- - - - tode_url_outbound_alter'); - // dsm($path, '$path'); - // dsm($options, '$options'); - // dsm($original_path, '$original_path'); - - $term = $options['entity']; - - }else{ - $args = explode('/', $original_path); - // dsm($args, 'args'); - if($args[0] == 'taxonomy' && $args[1] == 'term' && is_numeric($args[2]) ){ - $term = taxonomy_term_load($args[2]); - } - - } + // if(isset($options['entity_type']) && $options['entity_type'] == 'taxonomy_term'){ + // // dsm('- - - - tode_url_outbound_alter'); + // // dsm($path, '$path'); + // // dsm($options, '$options'); + // // dsm($original_path, '$original_path'); + // + // $term = $options['entity']; + // + // }else{ + // $args = explode('/', $original_path); + // // dsm($args, 'args'); + // if($args[0] == 'taxonomy' && $args[1] == 'term' && is_numeric($args[2]) ){ + // $term = taxonomy_term_load($args[2]); + // } + // + // } + # WARNING works only because nodeandtermrelink_url_outbound_alter() is trigered before this + if (preg_match('/^taxonomy\/term\/([0-9]*)$/', $path, $matches)) { + $term = taxonomy_term_load($matches[1]); + } if($term){ - // dsm($term, '$term'); - if($field = _tode_get_voc_tode_fields_def($term->vocabulary_machine_name)){ - # add if widget setting; + // dsm($term, '$term : '.$term->name); + if($field = _tode_get_voc_tode_field_def($term->vocabulary_machine_name)){ + // dsm($field, '$field'); + // $field_settings = field_info_instance_settings($field->type);//field_info_widget_settings($field->field_name); // + // dsm($field_settings, '$field_settings'); + # TODO add if widget setting; how to get the settings if (isset($field['widget']['settings']['redirect_term_to_node']) && $field['widget']['settings']['redirect_term_to_node']) { // dsm($field, '$field'); // dsm($options, '$options'); - $sr = $field['storage']['details']['sql']['FIELD_LOAD_CURRENT']; + $sr = $field['field_info_field']['storage']['details']['sql']['FIELD_LOAD_CURRENT']; foreach ($sr as $table => $column) { $query = db_select($table, 'ft'); $query->join('node', 'n', 'ft.entity_id = n.nid AND n.language = :language OR n.language = :language', array(':language' => $options['language']->language, ':language' => 'und')); @@ -1139,15 +1146,18 @@ function _tode_get_node_tode_fields_def($node){ return $tode_fields; } -function _tode_get_voc_tode_fields_def($voc_name){ +function _tode_get_voc_tode_field_def($voc_name){ $type_fields = field_info_instances('node'); // dsm($type_fields, '$type_fields'); foreach ($type_fields as $nodetype => $fields) foreach ($fields as $field_name => $field) if($field['widget']['type'] == 'tode'){ + // dsm($field, '$field'); $fieldinfos = field_info_field($field_name); + // dsm($fieldinfos, '$fieldinfos'); + $field['field_info_field'] = $fieldinfos; if($voc_name == $fieldinfos['settings']['allowed_values'][0]['vocabulary']) - return $fieldinfos; + return $field; } @@ -1156,9 +1166,10 @@ function _tode_get_voc_tode_fields_def($voc_name){ } function tode_get_nids_from_term($term, $language = false){ - $todefield = _tode_get_voc_tode_fields_def($term->vocabulary_machine_name); + - if($todefield){ + if($todefield = _tode_get_voc_tode_field_def($term->vocabulary_machine_name)){ + // $fieldinfos = field_info_field($todefield->field_name); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') ->fieldCondition($todefield['field_name'], 'tid', $term->tid); From c952bd330f6db5b0dec707da7e57286203581b6c Mon Sep 17 00:00:00 2001 From: bachy Date: Wed, 26 Sep 2012 16:36:56 +0200 Subject: [PATCH 20/24] redirect node to term alpha Signed-off-by: bachy --- tode.module | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/tode.module b/tode.module index 647db1ad..65aa9a33 100644 --- a/tode.module +++ b/tode.module @@ -120,6 +120,12 @@ function tode_field_widget_settings_form($field, $instance){ '#title' => t('Rewrite all term link to theire tode node ?'), '#default_value' => $settings['redirect_term_to_node'], ); + + $form['redirect_node_to_term'] = array( + '#type' => 'checkbox', + '#title' => t('Rewrite all node link to theire term node ?'), + '#default_value' => $settings['redirect_node_to_term'], + ); $form['show_create_tode'] = array( '#type' => 'checkbox', @@ -139,6 +145,8 @@ function _tode_widget_settings_maxlength_validate($element, &$form_state) { if (!is_numeric($value) || intval($value) != $value || $value <= 0) { form_error($element, t('"Maximum length" must be a positive integer.')); } + + # TODO checke that node to term and term to node can't be chexked together } /** @@ -977,6 +985,7 @@ function tode_url_outbound_alter(&$path, &$options, $original_path) { // dsm('tode_url_outbound_alter'); # terms url $term = false; + $node = false; // if(isset($options['entity_type']) && $options['entity_type'] == 'taxonomy_term'){ // // dsm('- - - - tode_url_outbound_alter'); // // dsm($path, '$path'); @@ -993,11 +1002,40 @@ function tode_url_outbound_alter(&$path, &$options, $original_path) { // } // // } - # WARNING works only because nodeandtermrelink_url_outbound_alter() is trigered before this + + if (preg_match('/^node\/([0-9]*)$/', $path, $matches)) { + $node = node_load($matches[1]); + } + + # WARNING works only because nodeandtermrelink_url_outbound_alter() is trigered before this (KADIST) if (preg_match('/^taxonomy\/term\/([0-9]*)$/', $path, $matches)) { $term = taxonomy_term_load($matches[1]); } - + + + if($node){ + // dsm($node, 'node'); + if($fields = _tode_get_node_tode_fields_def($node)){ + foreach ($fields as $field_name => $field) { + if (isset($field['widget']['settings']['redirect_node_to_term']) && $field['widget']['settings']['redirect_node_to_term']) { + dsm($field, '$field'); + $items = field_get_items('node', $node, $field_name); + dsm($items, 'items'); + $new_path = 'taxonomy/term/'.$items[0]['tid']; + if( $new_alias = drupal_get_path_alias($new_path) ){//, $options['language']->language + $path = $new_alias; + $original_path = $new_path; + $options['alias'] = TRUE; + }else{ + $path = $new_path; + } + break; + } + } + + } + } + if($term){ // dsm($term, '$term : '.$term->name); if($field = _tode_get_voc_tode_field_def($term->vocabulary_machine_name)){ From aa8698232d4b5d9dfc6794b5a18a76a551ee6cd9 Mon Sep 17 00:00:00 2001 From: bachy Date: Thu, 11 Oct 2012 18:23:30 +0200 Subject: [PATCH 21/24] field formatter "Tode" for term_reference Signed-off-by: bachy --- tode.module | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 4 deletions(-) diff --git a/tode.module b/tode.module index a12617db..9c7887a0 100644 --- a/tode.module +++ b/tode.module @@ -42,6 +42,9 @@ function tode_theme() { 'tode' => array( 'arguments' => array('element' => NULL), ), + 'tode_node_formatter' => array( + 'variables' => array('item' => NULL, 'viewmode' => 'full', 'nodes'=>NULL), + ), ); } @@ -861,10 +864,9 @@ function DESACTIVATED_tode_field_widget_form_alter(&$element, &$form_state, $con * */ function tode_form_alter(&$form, $form_state, $form_id){ - // dsm($form_id, 'tode form_alter form_id'); - /* - TODO block the deletion if tode term has children !! because this will delete them to … - */ + // dsm($form_id, 'tode form_alter form_id'); + // TODO block the deletion if tode term has children !! because this will delete them to … + if($form_id == 'test_node_form'){ // dsm($form_state); } @@ -1031,6 +1033,103 @@ function tode_url_outbound_alter(&$path, &$options, $original_path) { } } + +/** + * Implements hook_field_formatter_info(). + */ +function tode_field_formatter_info() { + return array( + 'tode' => array( + 'label' => t('tode (node of the term)'), + 'field types' => array('taxonomy_term_reference'), + 'settings'=>array('viewmode' => "full"), + ), + ); +} + +/** + * Implements hook_field_formatter_settings_form(). + */ +function tode_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { + $element = array(); + $display = $instance['display'][$view_mode]; + $settings = $display['settings']; + $formatter = $display['type']; + + if($formatter == 'tode'){ + if($todefield = _tode_get_voc_tode_fields_def($field['settings']['allowed_values'][0]['vocabulary'])){ + $entity_infos = entity_get_info(); + foreach ($entity_infos['node']['view modes'] as $viewmode => $value) { + $viewmode_options[$viewmode] = $value['label']; + } + + $element['viewmode'] = array( + '#type' => 'select', + '#title' => t('View mode'), + '#default_value' => $settings['viewmode'], + '#description' => t('select the view mode for the node'), + '#options' => $viewmode_options, + ); + + }else{ + // TODO: tell that vocabulary has any tode field + } + } + + return $element; +} + +/** + * Implements hook_field_formatter_settings_summary(). + */ +function tode_field_formatter_settings_summary($field, $instance, $view_mode) { + $display = $instance['display'][$view_mode]; + if($display['type'] == 'tode'){ + $settings = $display['settings']; + $summary = t('viewmode : %vm', array('%vm'=> isset($settings['viewmode']) ? $settings['viewmode'] : 'full') ); + return $summary; + } +} + +/** + * Implements hook_field_formatter_view(). + */ +function tode_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { + $element = array(); + $settings = $display['settings']; + + switch ($display['type']) { + case 'tode': + foreach ($items as $delta => $item) { + $term = taxonomy_term_load($item['tid']); + + $entitys = tode_get_nids_from_term($term); + + $nodes = array(); + if(isset($entitys['node'])){ + foreach ($entitys['node'] as $nid => $n) { + $node = node_load($nid); + $nodes[$nid] = $node; + } + $element[$delta] = array( + '#theme' => 'tode_node_formatter', + '#item' => $item, + '#viewmode' => $settings['viewmode'], + '#nodes'=> $nodes, + ); + } + } + break; + } + + return $element; +} + +function theme_tode_node_formatter($vars){ + // dsm($vars, 'theme_tode_node_formatter | vars'); + print render(entity_view('node', $vars['nodes'], $vars['viewmode'])); +} + /** * HELPERS */ From a7b1a91c6fa5d43193c426736bcc48f981a45820 Mon Sep 17 00:00:00 2001 From: bachy Date: Thu, 11 Oct 2012 18:54:11 +0200 Subject: [PATCH 22/24] bug fix Signed-off-by: bachy --- tode.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tode.module b/tode.module index cd9b4177..fa0288e8 100644 --- a/tode.module +++ b/tode.module @@ -1102,7 +1102,7 @@ function tode_field_formatter_settings_form($field, $instance, $view_mode, $form $formatter = $display['type']; if($formatter == 'tode'){ - if($todefield = _tode_get_voc_tode_fields_def($field['settings']['allowed_values'][0]['vocabulary'])){ + if($todefield = _tode_get_voc_tode_field_def($field['settings']['allowed_values'][0]['vocabulary'])){ $entity_infos = entity_get_info(); foreach ($entity_infos['node']['view modes'] as $viewmode => $value) { $viewmode_options[$viewmode] = $value['label']; From 0e49c6cedf51b8b7d9ee90eb407a2eabaf1b6e31 Mon Sep 17 00:00:00 2001 From: bachy Date: Fri, 9 Nov 2012 11:53:36 +0100 Subject: [PATCH 23/24] bug fixe : with entity translation Signed-off-by: bachy --- tode.module | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tode.module b/tode.module index fa0288e8..87983f2a 100644 --- a/tode.module +++ b/tode.module @@ -478,7 +478,8 @@ function tode_node_submit($node, $form, &$form_state) { $values = _tode_prefix_form($form_state['values'][$prefix], $prefix.'_', FALSE); // dsm($values, 'values'); - if(module_exists('i18n_taxonomy') && $language != 'und' && $language != $default_language){ + if($field['field_info_field']['translatable'] && module_exists('i18n_taxonomy') && $language != 'und' && $language != $default_language){ + // $field['field_info_field']['translatable'] is about entity translation module $context= array('term',$values['tid'],'name'); i18n_string_textgroup('taxonomy')->update_translation($context, $language, $tode_field_term_value['name']); @@ -491,9 +492,6 @@ function tode_node_submit($node, $form, &$form_state) { $values['parent'] = array($parent_tid => $parent_tid); - - // if(!module_exists('i18n_taxonomy') || $language == 'und' || $language == $default_language){ - // define the form_state for term_form submit $new_term_form_state = array( 'build_info'=>array( @@ -509,8 +507,6 @@ function tode_node_submit($node, $form, &$form_state) { // dsm($new_term_form_state, 'form_state'); drupal_form_submit('taxonomy_form_term', $new_term_form_state); - // }else{ - } @@ -1275,8 +1271,11 @@ function _tode_get_node_tode_fields_def($node){ #get the tode node fields $tode_fields = array(); foreach ($type_fields[$node->type] as $field_name => $field) { - if($field['widget']['type'] == 'tode') + if($field['widget']['type'] == 'tode'){ + $fieldinfos = field_info_field($field_name); + $field['field_info_field'] = $fieldinfos; $tode_fields[$field_name] = $field; + } } @@ -1303,9 +1302,8 @@ function _tode_get_voc_tode_field_def($voc_name){ } function tode_get_nids_from_term($term, $language = false){ - - if($todefield = _tode_get_voc_tode_field_def($term->vocabulary_machine_name)){ + if(isset($term->vocabulary_machine_name) && $todefield = _tode_get_voc_tode_field_def($term->vocabulary_machine_name)){ // $fieldinfos = field_info_field($todefield->field_name); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node') From 3eaa5817e0b8783825d5b17f0116e3bdc07150f3 Mon Sep 17 00:00:00 2001 From: bachy Date: Fri, 7 Dec 2012 10:59:22 +0100 Subject: [PATCH 24/24] change readme.txt content Signed-off-by: bachy --- README.txt | 1 - readme.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/README.txt b/README.txt index cad2ab58..e69de29b 100644 --- a/README.txt +++ b/README.txt @@ -1 +0,0 @@ -!!! this module is not ready tu use !!! \ No newline at end of file diff --git a/readme.txt b/readme.txt index cad2ab58..e69de29b 100644 --- a/readme.txt +++ b/readme.txt @@ -1 +0,0 @@ -!!! this module is not ready tu use !!! \ No newline at end of file