Explorar el Código

redirect node to term alpha

Signed-off-by: bachy <git@g-u-i.net>
bachy hace 12 años
padre
commit
c952bd330f
Se han modificado 1 ficheros con 40 adiciones y 2 borrados
  1. 40 2
      tode.module

+ 40 - 2
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)){