array( // // 'title' => t(''), // // 'description' => t(''), // // ); // } $perms['access taxonomy terms page'] = array( 'title' => t('access taxonomy terms page'), 'description' => t(''), ); $perms['access fr2en materio'] = array( 'title' => t('access fr2en materio'), 'description' => t(''), ); return $perms; } function materio_taxonomy_menu_alter(&$items) { $items['taxonomy/term/%taxonomy_term']['access arguments'] = array('access taxonomy terms page'); $items['taxonomy/term/%taxonomy_term/view']['access arguments'] = array('access taxonomy terms page'); $items['taxonomy/term/%taxonomy_term/feed']['access arguments'] = array('access taxonomy terms page'); } /** * Implementation of hook_query_term_access_alter(). * * debug de i18n_select_query_term_access_alter() * qui filtre les terms par language mm pour les vocabulaires en mode localized. * utile pour la recherche avancée de materio_search_api materio_search_api_advanced_search_form() * * * Inutile si i18n_taxonomy module is desactivate */ function DISABLED_materio_taxonomy_query_term_access_alter(QueryAlterableInterface $query) { // dsm($query, 'materio taxo query'); if(!module_exists('i18n_taxonomy')) return; $conditions =& $query->conditions(); # roll over condition first time to determine i18n_voc_mode $i18n_voc_mode = 0; foreach ($conditions as $condition) { if (is_array($condition)) { // dsm($condition, 'conditon '.$condition['field']); if($condition['field'] == 't.vid'){ $vid = $condition['value']; $i18n_voc_mode = module_exists('i18n_taxonomy') ? i18n_taxonomy_vocabulary_mode($vid) : 0; // dsm($i18n_voc_mode, 'i18n_voc_mode'); } } } # roll over conditions a second time to re-alter/fixe language selection # i18n vocabulary mode is 1 for localized terms if($i18n_voc_mode == 1){ foreach ($conditions as $index => $condition) { if (is_array($condition)) { // dsm($condition, 'conditon '.$condition['field']); if($condition['field'] == 't.language' && $i18n_voc_mode == 1){ $l = array('und'); $ll = i18n_language_list(); // dsm($ll, 'list language'); foreach ($ll as $langcode => $langname) { $l[] = $langcode; } $conditions[$index]['value'] = $l; } } } } } /** * Implements hook_menu(). */ function materio_taxonomy_menu() { $items['admin/structure/taxonomy/fr2en'] = array( 'title' => 'fr2en taglibres', 'page callback' => 'drupal_get_form', 'page arguments' => array('materio_taxonomy_fr2en_form'), 'access arguments' => array('access fr2en materio'), 'type' => MENU_NORMAL_ITEM, 'weight' => 999, ); return $items; } function materio_taxonomy_fr2en_form(){ $form['description'] = array( '#type' => 'markup', '#markup' => t('convert tag libres terms name frome french to english from csv file'), ); $form['batch'] = array( '#type' => 'select', '#title' => 'Choose batch', '#options' => array( 'fr2en' => t('fr2en'), 'en2fr' => t('en2fr'), ), ); $form['submit'] = array( '#type' => 'submit', '#value' => 'Go', ); return $form; } function materio_taxonomy_fr2en_form_submit($form, &$form_state) { $function = 'materio_taxonomy_fr2en'; // Reset counter for debug information. $_SESSION['http_request_count'] = 0; // Execute the function named batch_example_1 or batch_example_2. $batch = $function($form_state['values']['batch']); batch_set($batch); } function materio_taxonomy_fr2en($op){ $file = drupal_get_path('module', 'materio_taxonomy')."/assets/taglibres_".$op.".csv"; $data = array(); if (($handle = fopen($file, "r")) !== FALSE) { while (($line = fgetcsv($handle, 1000, ",")) !== FALSE) { $data[$line[0]] = $line[1]; } fclose($handle); }else{ drupal_set_message("fopen csv file failed"); return; } // get term list from vocabulary $tags = taxonomy_get_tree(4); $operations = array(); foreach ($tags as $tid => $t) { if($t->name){ if(isset($data[$t->name])){ $operations[] = array( 'materio_taxonomy_fr2en_batch', array( $data[$t->name], $t ) ); } } } $batch = array( "operations" => $operations, "finished" => "materio_taxonomy_fr2en_batch_finished" ); return $batch; } function materio_taxonomy_fr2en_batch($name, $t, &$context){ $oldname = $t->name; $t->name = $name; taxonomy_term_save($t); // $cont= array('term',$t->tid,'name'); // i18n_string_textgroup('taxonomy')->update_translation($cont, 'fr', $oldname); // https://www.drupal.org/project/entity_translation_export_import $context['message'][] = $oldname .' -> '. $name; $_SESSION['http_request_count']++; } function materio_taxonomy_fr2en_batch_finished($success, $results, $operations){ if($success){ drupal_set_message('All terms converted'); } }