From 35a5eb3a60fb9054cebe8eb5f337c1e1c654e997 Mon Sep 17 00:00:00 2001 From: bachy Date: Tue, 22 May 2012 22:40:31 +0200 Subject: [PATCH 1/2] 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 2/2] 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)){