diff --git a/sites/all/modules/contrib/page_title/modules/node.page_title.inc b/sites/all/modules/contrib/page_title/modules/node.page_title.inc index e67a572..5654480 100644 --- a/sites/all/modules/contrib/page_title/modules/node.page_title.inc +++ b/sites/all/modules/contrib/page_title/modules/node.page_title.inc @@ -29,13 +29,32 @@ function node_page_title_alter(&$title) { function node_page_title_pattern_alter(&$pattern, &$types) { if ((arg(0) == 'node' && is_numeric(arg(1)))) { $types['node'] = menu_get_object(); + + // Initializing our default key for that node + $default_pattern_key = 'page_title_type_'. $types['node']->type; + + // If a page title has been set for the viewed node, then get it, else get the right pattern + if( !empty($types['node']->page_title) ) { + $pattern = $types['node']->page_title; + } else { + + // If a language exists for this node, we try to use page title pattern related to that language + // If the title pattern for that language is empty, we use the default one + if (!empty($types['node']->language)) { + $lang_pattern_key = $default_pattern_key . '_' . $types['node']->language; + $lang_pattern = variable_get($lang_pattern_key, ''); + } + $pattern_key = empty($lang_pattern) ? $default_pattern_key : $lang_pattern_key; + + // Get the right pattern in function of the determined key above + $pattern = variable_get($pattern_key, ''); + + } // If the node has any taxonomy, grab the first time and pass it over to be passed as a token. // TODO: Handle multiple terms? Only pass specific terms per content type? if (!empty($types['node']->taxonomy)) { $types['taxonomy'] = current($types['node']->taxonomy); } - - $pattern = variable_get('page_title_type_'. $types['node']->type, ''); } } diff --git a/sites/all/modules/contrib/page_title/page_title.admin.inc b/sites/all/modules/contrib/page_title/page_title.admin.inc index 5ef7c95..b531f8a 100644 --- a/sites/all/modules/contrib/page_title/page_title.admin.inc +++ b/sites/all/modules/contrib/page_title/page_title.admin.inc @@ -16,7 +16,6 @@ function page_title_admin_settings() { // Define a default looking 'form element' for setting. $showfield_form_element = array('#type' => 'checkbox', ); - // Define a default looking 'form element' for setting. $pattern_form_element = array( '#type' => 'textfield', @@ -24,7 +23,6 @@ function page_title_admin_settings() { '#maxlength' => 256, ); - // Set the theme callback for the patterns section $form['patterns'] = array( '#type' => 'fieldset', @@ -33,7 +31,6 @@ function page_title_admin_settings() { '#theme' => 'page_title_admin_settings' ); - // Define the basic scope column values $form['patterns']['scope'] = array( 'page_title_default' => array('#type' => 'markup', '#value' => t('Global'), ), @@ -100,7 +97,16 @@ function page_title_admin_settings() { // Definate the patterns per-node-type $types = node_get_types(); + + // List of all enabled languages + if (module_exists('locale')) { + $langs = locale_language_list(); + } else { + $langs = array(); + } + foreach ($types as $type) { + // Define the node-type key $key = 'page_title_type_'. $type->type; @@ -114,9 +120,25 @@ function page_title_admin_settings() { $form['patterns']['showfield'][$key .'_showfield'] = array( '#default_value' => variable_get($key .'_showfield', 0), ) + $showfield_form_element; - - $form['patterns']['scope'][$key] = array('#type' => 'markup', '#value' => t('Node'), ); - } + + // We define patterns for all the languages available in Drupal (activated or not) + foreach ($langs as $langcode => $langname){ + + // Key language dependant variables : pattern + $lang_key = $key . '_' . $langcode; + + // Content Type Entry for language : pattern + $form['patterns']['pattern'][$lang_key] = array( + '#title' => t('Content Type - %type - %lang', array('%type' => $type->name, '%lang' => $langname)), + '#default_value' => variable_get($lang_key, ''), + ) + $pattern_form_element; + + // Content Type Entry for language : scope + $form['patterns']['scope'][$lang_key] = array('#type' => 'markup', '#value' => t('Node'), ); + + } // end foreach $langs + + } // end foreach $types // Definate the patterns per-vocab-type - if Taxonomy Module is enabled diff --git a/sites/all/modules/contrib/page_title/page_title.module b/sites/all/modules/contrib/page_title/page_title.module index 6282853..d707b25 100644 --- a/sites/all/modules/contrib/page_title/page_title.module +++ b/sites/all/modules/contrib/page_title/page_title.module @@ -111,32 +111,63 @@ function page_title_theme() { * Updates settings after a node type change. */ function page_title_node_type($op, $info) { + + // List of all enabled languages + if (module_exists('locale')) { + $langs = locale_language_list(); + } else { + $langs = array(); + } + + // Keys prefix + $oldkey_prefix = 'page_title_type_'. $info->old_type; + $newkey_prefix = 'page_title_type_'. $info->type; + // Handle a content type rename if ($op == 'update' && !empty($info->old_type) && $info->type != $info->old_type) { - // Load the old node type settings. - $temp = variable_get('page_title_type_'. $info->old_type, ''); - - // If the settings aren't empty, then save them into the new type - if (!empty($temp)) { - variable_set('page_title_type_'. $info->type, $temp); - } - - // Delete the old setting - variable_del('page_title_type_'. $info->old_type); - - // Essentially, do the same as above but with the _showfield suffix for the node type - $temp = variable_get('page_title_type_'. $info->old_type .'_showfield', 0); + + // 1. Save showfield setting from old node type + $temp = variable_get($oldkey_prefix .'_showfield', 0); if ($temp) { - variable_set('page_title_type_'. $info->type .'_showfield', $temp); + variable_set($newkey_prefix .'_showfield', $temp); } - variable_del('page_title_type_'. $info->old_type .'_showfield'); - + variable_del($oldkey_prefix .'_showfield'); + + // 2. Save patterns of old node type for each languages available on the system + foreach ($langs as $langcode => $langname) { + + // Key for the old and new node type per language + $oldkey_lang = $oldkey_prefix . '_' . $langcode; + $newkey_lang = $newkey_prefix . '_' . $langcode; + + // Load the old node type setting + $temp = variable_get($oldkey_lang, ''); + + // If the setting is not empty, then save it with the new type + if (!empty($temp)) { + variable_set($newkey_lang, $temp); + } + + // Delete the old setting + variable_del($oldkey_lang); + + } // end foreach $alllangs + } - // If deleted, remove the variables + // Handle a content type deletion if ($op == 'delete') { - variable_del('page_title_type_'. $info->type); - variable_del('page_title_type_'. $info->type .'_showfield'); + + // Removing default pattern and showfield + variable_del($newkey_prefix); + variable_del($newkey_prefix .'_showfield'); + + // Removing patterns associated to a language + foreach ($langs as $langcode => $langname) { + $newkey_lang = $newkey_prefix . '_' . $langcode; + variable_del($newkey_lang); + } + } } @@ -145,15 +176,23 @@ function page_title_node_type($op, $info) { * Implementation of hook_form_alter(). */ function page_title_form_alter(&$form, $form_state, $form_id) { + // If we dont have permission to set the title then we need to abort this alter now! if (!user_access('set page title')) return; // Check we're editing a node and also check that the node type's 'show field' is enabled if ($form['#id'] == 'node-form') { - $key = 'page_title_type_'. $form['type']['#value'] .'_showfield'; - if (variable_get($key, 0)) { - $page_title = isset($form['#node']->page_title) ? $form['#node']->page_title : NULL; - + + $showfield_key = 'page_title_type_'. $form['type']['#value'] .'_showfield'; + + if (variable_get($showfield_key, 0)) { + + $default_pattern_key = 'page_title_type_'. $form['type']['#value']; + // If a language exists for this node, we use the language related page title pattern, else we use the default pattern + $pattern_key = empty($form['#node']->language) ? $default_pattern_key : $default_pattern_key . '_' . $form['#node']->language; + + $page_title = isset($form['#node']->page_title) ? $form['#node']->page_title : variable_get($pattern_key, NULL); + // If we have vertical tabs installed, we need to render the form element slightly differently $show_vertical_tabs = FALSE; if (module_exists('vertical_tabs')) { @@ -207,7 +246,6 @@ function page_title_form_alter(&$form, $form_state, $form_id) { } } - /** * Implementation of hook_form_FORM_ID_alter(). */ @@ -249,6 +287,26 @@ function page_title_form_forum_form_forum_alter(&$form, &$form_state) { } } +/** + * Implementation of hook_form_FORM_ID_alter(). + * Case when we're deleting a language, we need to remove variables from variable table + * TODO maybe it's worth keeping the variables, in case the language is added again ? + */ +function page_title_form_locale_languages_delete_form_alter(&$form, &$form_state) { + $form['#submit'][] = 'page_title_locale_languages_delete_form_submit'; +} + +/** + * Submit handler for the locale_languages_delete_form element added in the hook_form_alter() above. + * TODO there may be a cleaner way to do that + */ +function page_title_locale_languages_delete_form_submit($form, $form_state) { + // Remove all variables from variable table associated to the language deleted + // ie: begins with 'page_title_' and ends with '$lang' + $regexp = "^page_title_(.)*_" . $form['langcode']['#value'] . "{1}$"; + $query = "DELETE FROM {variable} WHERE name REGEXP '%s'"; + db_query($query, $regexp); +} /** * Implementation of hook_form_FORM_ID_alter(). @@ -283,6 +341,10 @@ function page_title_form_user_profile_form_alter(&$form, &$form_state) { * Implementation of hook_form_FORM_ID_alter(). */ function page_title_form_node_type_form_alter(&$form, &$form_state) { + + // key by content type + $key = 'page_title_type_'. $form['#node_type']->type; + // Alter the node type form - allows easy access to the per-content type page title settings $form['page_title'] = array( '#type' => 'fieldset', @@ -299,13 +361,13 @@ function page_title_form_node_type_form_alter(&$form, &$form_state) { '#options' => array( 'show_field' => t('Show field'), ), - '#default_value' => variable_get('page_title_type_'. $form['#node_type']->type .'_showfield', 0) ? array('show_field') : array(), + '#default_value' => variable_get( $key .'_showfield', 0) ? array('show_field') : array(), ); $form['page_title']['pattern'] = array( '#type' => 'textfield', '#title' => t('Page Title Pattern'), - '#default_value' => variable_get('page_title_type_'. $form['#node_type']->type, ''), + '#default_value' => variable_get( $key , ''), '#description' => t('Enter the Page Title pattern you want to use for this node type. For more information, please use the !link settings page', array('!link' => l('Page Title', 'admin/content/page_title'))), ); @@ -317,9 +379,13 @@ function page_title_form_node_type_form_alter(&$form, &$form_state) { * Submit handler for the node_type_form element added in the hook_form_alter() above. */ function page_title_node_type_form_submit($form, &$form_state) { + + $key_type = 'page_title_type_'. $form_state['values']['type']; + $show_field = $form_state['values']['page_title']['show_field']['show_field'] ? 1 : 0; - variable_set('page_title_type_'. $form_state['values']['type'] .'_showfield', $show_field); - variable_set('page_title_type_'. $form_state['values']['type'], $form_state['values']['page_title']['pattern']); + + variable_set($key_type .'_showfield', $show_field); + variable_set($key_type, $form_state['values']['page_title']['pattern']); // For some reason the node module adds the fieldset as a separate entry in the variables table... we dont want this! variable_del('page_title_'. $form_state['values']['type']); @@ -441,7 +507,7 @@ function page_title_load_title($id, $type) { /** * Wrapper for old function... - * NOTE: This has been depricated in favor of page_title_load_title(). + * @deprecated Use page_title_load_title() instead. */ function page_title_node_get_title($nid) { return page_title_load_title($nid, 'node'); @@ -450,7 +516,7 @@ function page_title_node_get_title($nid) { /** * Legacy page title setting function... - * NOTE: This has been deprecated in favour of hook_page_title_alter(). + * @deprecated Use hook_page_title_alter() instead. */ function page_title_set_title($title = NULL) { static $stored_title; @@ -595,7 +661,6 @@ function _page_title_build_views_keys($view_name, $display_id) { return 'page_title-'. implode('-', array_filter(array($view_name, $display_id))); } - /** * Form Alter handler for the views ui config form (used for filters and args) */