Merge branch '7.x' of ssh://ssh.g-u-i.net/module-tode into 7.x

This commit is contained in:
bachy 2012-10-11 18:25:43 +02:00
commit 900155d078

View File

@ -123,6 +123,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',
@ -142,6 +148,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
}
/**
@ -782,7 +790,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');
@ -976,34 +984,71 @@ 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'];
$node = 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]);
// }
//
// }
}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 (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');
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'));
@ -1238,15 +1283,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;
}
@ -1255,9 +1303,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);