Compare commits

...
2 Commits
Author SHA1 Message Date
bachy 4a958da4df 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 <git@g-u-i.net>
2012-04-16 23:07:27 +02:00
bachy 9d97a0b7b7 tode_url_outbound_alter improvement (path_alias)
Signed-off-by: bachy <git@g-u-i.net>
2012-03-18 14:38:35 +01:00
2 changed files with 89 additions and 86 deletions
-19
View File
@@ -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;
}
+89 -67
View File
@@ -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
*
* <?php
* // automatic node titles php snippet for translation
* $items = field_get_items('node', $node, 'field_tode_program');
* return t($items[0]['name']);
* ?>
*
*
*/
@@ -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{
}
@@ -687,7 +704,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');
@@ -740,15 +757,20 @@ function _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'])){
@@ -773,7 +795,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,31 +811,30 @@ 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'] = '<div class="tode-add-modal-wrapper">';
$element['#suffix'] .= '</div></div>';
}
// dsm($element, '$element');
}
}
@@ -947,43 +968,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
*/