Commit 93e51319 authored by Nicholas Thompson's avatar Nicholas Thompson
Browse files

#1169424 - fixed the D7 branch to use the Vocab Machine Names, rather than...

#1169424 - fixed the D7 branch to use the Vocab Machine Names, rather than VID. Thanks to Ravi.K and rickvug for testing and patching. Appreciated.
parent e3b1e365
......@@ -15,7 +15,7 @@ function forum_page_title_alter(&$title) {
// container or forum (rather than root).
if ( !strncmp($menu_item['path'], 'forum/%', 7) &&
($term = menu_get_object('taxonomy_term')) &&
variable_get('page_title_vocab_' . $term->vid . '_showfield', 0) &&
variable_get('page_title_vocab_' . $term->vocabulary_machine_name . '_showfield', 0) &&
($forum_title = page_title_load_title($term->tid, 'term')) ) {
$title = $forum_title;
}
......@@ -32,9 +32,12 @@ function forum_page_title_pattern_alter(&$pattern, &$types) {
if ( !strncmp($menu_item['path'], 'forum/%', 7) &&
($forum = menu_get_object('forum_forum', 1)) ) {
$types['term'] = $forum;
$forum_vid = variable_get('forum_nav_vocabulary', '');
$pattern = variable_get('page_title_vocab_' . $forum_vid, '');
$types['vocabulary'] = taxonomy_vocabulary_load($forum_vid);
$form_vocab = taxonomy_vocabulary_load($forum_vid);
$pattern = variable_get('page_title_vocab_' . $forum_vocab->machine_name, '');
$types['vocabulary'] = $forum_vocab;
}
// Otherwise it's the root - let's grab the root pattern.
elseif ($menu_item['path'] == 'forum') {
......
......@@ -29,7 +29,8 @@ function page_title_page_title_pattern_alter(&$pattern, &$types) {
// If frontpage, then use the frontpage pattern and set the title.
if (drupal_is_front_page()) {
// Get the frontpage pattern
$pattern = variable_get('page_title_front', '[site:name] | [site:slogan]');
$settings = page_title_get_settings();
$pattern = variable_get('page_title_front', $settings['page_title_front']['default']);
}
}
......@@ -46,7 +47,7 @@ function page_title_page_title_settings() {
'show field' => FALSE,
'description' => 'This pattern will be used as a <em>fallback</em> (ie, when no other pattern is defined)',
'weight' => -50,
'default' => '[page-title] | [site-name]',
'default' => '[current-page:page-title] | [site:name]',
),
'page_title_front' => array(
'label' => 'Fronpage',
......@@ -54,7 +55,7 @@ function page_title_page_title_settings() {
'show field' => FALSE,
'description' => 'This pattern will be used for the site frontpage',
'weight' => -49,
'default' => '[site-name] | [site-slogan]',
'default' => '[site:name] | [site:slogan]',
),
'page_title_pager_pattern' => array(
'label' => 'Pager Suffix',
......
......@@ -14,7 +14,7 @@ function taxonomy_page_title_alter(&$title) {
// If we're looking at a taxonomy term page, get the term title.
if ( !strncmp($menu_item['path'], 'taxonomy/term/%', 15) &&
($term = menu_get_object('taxonomy_term', 2)) &&
variable_get('page_title_vocab_' . $term->vid . '_showfield', 0) &&
variable_get('page_title_vocab_' . $term->vocabulary_machine_name . '_showfield', 0) &&
($term_title = page_title_load_title($term->tid, 'term')) ) {
$title = $term_title;
}
......@@ -31,7 +31,7 @@ function taxonomy_page_title_pattern_alter(&$pattern, &$types) {
if ( !strncmp($menu_item['path'], 'taxonomy/term/%', 15) &&
($term = menu_get_object('taxonomy_term', 2)) ) {
$types['term'] = $term;
$pattern = variable_get('page_title_vocab_' . $term->vid, '');
$pattern = variable_get('page_title_vocab_' . $term->vocabulary_machine_name, '');
}
}
......@@ -44,7 +44,7 @@ function taxonomy_page_title_settings() {
$vocabs = taxonomy_get_vocabularies();
foreach ($vocabs as $vocab) {
$settings['page_title_vocab_' . $vocab->vid] = array(
$settings['page_title_vocab_' . $vocab->machine_name] = array(
'label' => 'Vocabulary - %vocab_name',
'label arguments' => array('%vocab_name' => $vocab->name),
'scopes' => array('global', 'term', 'vocabulary'),
......
......@@ -60,6 +60,31 @@ function page_title_update_6200() {
}
/**
* Implementation of hook_update_n().
* Rename all the Vocabulary settings to reference by the new Machine Name, rather than Vocab ID.
*/
function page_title_update_7200() {
$ret = array();
foreach(taxonomy_get_vocabularies() as $vocab) {
$page_title_vocab_settings = variable_get("page_title_vocab_{$vocab->vid}", FALSE);
$page_title_vocab_showfield = variable_get("page_title_vocab_{$vocab->vid}_showfield", FALSE);
if ($page_title_vocab_settings) {
variable_set("page_title_vocab_{$vocab->machine_name}", $page_title_vocab_settings);
}
if ($page_title_vocab_showfield) {
variable_set("page_title_vocab_{$vocab->machine_name}_showfield", $page_title_vocab_showfield);
}
variable_del("page_title_vocab_{$vocab->vid}_showfield");
variable_del("page_title_vocab_{$vocab->vid}");
}
return $ret;
}
/**
* Implementation of hook_uninstall().
*/
......@@ -87,6 +112,10 @@ function page_title_uninstall() {
if (module_exists('taxonomy')) {
$vocabs = taxonomy_get_vocabularies();
foreach ($vocabs as $vid => $vocab) {
variable_del("page_title_vocab_{$vocab->machine_name}");
variable_del("page_title_vocab_{$vocab->machine_name}_showfield");
// Legacy delete - just in case the uninstall is happening befoer update 7200
variable_del("page_title_vocab_{$vid}");
variable_del("page_title_vocab_{$vid}_showfield");
}
......
......@@ -253,7 +253,7 @@ function page_title_form_taxonomy_form_term_alter(&$form, $form_state) {
//if ($form['delete']['#value'] === TRUE) return;
// Check the term's vocab has the show field enabled
if (variable_get('page_title_vocab_' . $form['#vocabulary']->vid . '_showfield', 0)) {
if (variable_get('page_title_vocab_' . $form['#vocabulary']->machine_name . '_showfield', 0)) {
$form['advanced']['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
......@@ -272,9 +272,10 @@ function page_title_form_taxonomy_form_term_alter(&$form, $form_state) {
*/
function page_title_form_forum_form_container_alter(&$form, $form_state) {
$forum_vid = variable_get('forum_nav_vocabulary', 0);
$forum_vocab = taxonomy_vocabulary_load($forum_vid);
// Check the forum vocab has the show field enabled
if (variable_get('page_title_vocab_' . $forum_vid . '_showfield', 0)) {
if (variable_get('page_title_vocab_' . $forum_vocab->machine_name . '_showfield', 0)) {
$form['page_title'] = array(
'#type' => 'textfield',
'#title' => t('Page title'),
......@@ -545,7 +546,8 @@ function page_title_page_get_title($raw = FALSE) {
// If pattern is empty (either if the type is not overridable or simply not set) fallback to the default pattern
if (empty($page_title_pattern)) {
$page_title_pattern = variable_get('page_title_default', '[current-page:page-title] | [site:name]');
$settings = page_title_get_settings();
$page_title_pattern = variable_get('page_title_default', $settings['page_title_default']['default']);
}
// Append the pattern for pages with a pager on them
......@@ -700,9 +702,23 @@ function page_title_views_plugins() {
/**
* Get the Page Title Setttings
*/
function page_title_get_settings() {
function page_title_get_settings($flush = FALSE) {
static $settings = NULL;
// Flush the settings, if set.
if ($flush) {
$settings = NULL;
cache_clear_all('page_title:settings');
}
// If we have it statically cached, return it.
if (!empty($settings)) {
return $settings;
}
// Get from the cache, if present
if ($cache = cache_get('page_title:settings')) {
$settings = $cache->data;
return $cache->data;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment