diff --git a/taxonomy_title.admin.inc b/taxonomy_title.admin.inc index a0e401a..aeb14bb 100644 --- a/taxonomy_title.admin.inc +++ b/taxonomy_title.admin.inc @@ -7,18 +7,24 @@ function taxonomy_title_admin_settings(){ $form = array(); - + // Get all taxonomy vocabularies. $vocabs = taxonomy_get_vocabularies(); - + // Set up place holders for options. $heading_options = array(); $page_title_options = array(); - + // Set up holders for default values. $heading_defaults = variable_get('taxonomy_title_headings', array()); $page_title_defaults = variable_get('taxonomy_title_page_titles', array()); - + + $form['settings'] = array( + '#theme' => 'taxonomy_title_admin_settings', + ); + + $link = theme('token_tree_link', array('text' => 'Browse available tokens', 'token_types' => array('term'))); + foreach ($vocabs as $vid => $vocab) { $heading_options[$vid] = $vocab->name; $page_title_options[$vid] = $vocab->name; @@ -28,24 +34,26 @@ function taxonomy_title_admin_settings(){ if (!isset($page_title_defaults[$vid])) { $page_title_defaults[$vid] = $vid; } + + $form['settings']['taxonomy_title_default_' . $vid] = array( + '#type' => 'textfield', + '#description' => t('Leave blank for none.') . ' ' . $link, + '#default_value' => variable_get('taxonomy_title_default_' . $vid, ''), + ); } - $form['settings'] = array( - '#theme' => 'taxonomy_title_admin_settings', - ); - $form['settings']['taxonomy_title_headings'] = array( '#type' => 'checkboxes', '#options' => $heading_options, '#default_value' => $heading_defaults, ); - + if (!module_exists('page_title') && !module_exists('metatag')) { $form['settings']['taxonomy_title_page_titles'] = array( '#type' => 'checkboxes', '#options' => $page_title_options, '#default_value' => $page_title_defaults, - ); + ); } else { $form['settings']['taxonomy_title_page_titles'] = array( @@ -56,13 +64,13 @@ function taxonomy_title_admin_settings(){ ); $form['settings']['notice'] = array( '#weight' => 2, - '#markup' => '

' . t('* Since you have either the page title module or - the metatag module enabled, this module will be unable to affect the - title tags of your pages. If you would like taxonomy titles to appear - in your title tags, please configure that module to use the provided + '#markup' => '

' . t('* Since you have either the page title module or + the metatag module enabled, this module will be unable to affect the + title tags of your pages. If you would like taxonomy titles to appear + in your title tags, please configure that module to use the provided tokens. Example: [term-title]') . '

', ); } - + return system_settings_form($form); -} \ No newline at end of file +} diff --git a/taxonomy_title.module b/taxonomy_title.module index 5ed7c30..d3925e7 100755 --- a/taxonomy_title.module +++ b/taxonomy_title.module @@ -127,6 +127,12 @@ function taxonomy_title_process_page(&$variables) { */ function _taxonomy_title_get_title($tid) { $title = db_query("SELECT title FROM {taxonomy_title} WHERE tid = :tid", array(':tid' => $tid))->fetchField(); + if ($title == FALSE) { + // Check for global default value. + $term = taxonomy_term_load($tid); + $default = variable_get('taxonomy_title_default_' . $term->vid, ''); + $title = token_replace($default, array('term' => $term)); + } if (function_exists('i18n_string_translate')) { $title = i18n_string_translate(array('taxonomy_title', 'term', $tid, 'title'), $title, array('sanitize' => FALSE)); } diff --git a/taxonomy_title.theme.inc b/taxonomy_title.theme.inc index 9d175e3..bb42443 100644 --- a/taxonomy_title.theme.inc +++ b/taxonomy_title.theme.inc @@ -11,15 +11,16 @@ function theme_taxonomy_title_admin_settings($variables) { $form = $variables['form']; if (!module_exists('page_title') && !module_exists('metatag')) { - $title_head = t('Affect title tag'); - } + $title_head = t('Change title tag'); + } else { - $title_head = t('Affect title tag *'); + $title_head = t('Change title tag *'); } $header = array( - t('Terms in vocabulary'), - array('data' => t('Affect Heading tag'), 'class' => 'checkbox'), + t('Terms in vocabulary'), + t('Global default value'), + array('data' => t('Affect Heading tag'), 'class' => 'checkbox'), array('data' => $title_head, 'class' => 'checkbox'), ); @@ -27,10 +28,12 @@ function theme_taxonomy_title_admin_settings($variables) { foreach($form['taxonomy_title_page_titles']['#options'] as $vid => $name) { $row = array(); $row[] = check_plain($name); + $row[] = drupal_render($form['taxonomy_title_default_' . $vid]); unset($form['taxonomy_title_headings'][$vid]['#title']); $row[] = array('data' => drupal_render($form['taxonomy_title_headings'][$vid]), 'class' => 'checkbox'); unset($form['taxonomy_title_page_titles'][$vid]['#title']); $row[] = array('data' => drupal_render($form['taxonomy_title_page_titles'][$vid]), 'class' => 'checkbox'); + $rows[] = $row; } @@ -41,7 +44,12 @@ function theme_taxonomy_title_admin_settings($variables) { $title_path = drupal_get_path('module', 'taxonomy_title') . '/includes/' . 'title.png'; $title_example = theme('image', array('path' => $title_path)); - $rows[] = array(t('Example'), array('data' => $heading_example, 'class' => 'checkbox'), array('data' => $title_example, 'class' => 'checkbox')); + $rows[] = array( + t('Example'), + array('data' => ''), + array('data' => $heading_example, 'class' => 'checkbox'), + array('data' => $title_example, 'class' => 'checkbox'), + ); // Create the table inside the form. $form['settings'] = array(