Commit 9f0335cf authored by Nicholas Thompson's avatar Nicholas Thompson
Browse files

Bringing the D7 branch inline with the masive settings refactoring from D6....

Bringing the D7 branch inline with the masive settings refactoring from D6. Settings are now a hook.
parent 8ef2a246
......@@ -32,3 +32,19 @@ function blog_page_title_pattern_alter(&$pattern, &$types) {
$pattern = variable_get('page_title_blog', '');
}
}
/**
* Implementation of hook_page_title_settings().
*/
function blog_page_title_settings() {
return array(
'page_title_blog' => array(
'label' => 'Blog Homepage',
'scopes' => array('global', 'user'),
'show field' => FALSE,
'description' => 'This pattern will be used for a users blog page (ie <code>/blog/1</code>)',
),
);
}
......@@ -60,3 +60,22 @@ function comment_page_title_pattern_alter(&$pattern, &$types) {
}
}
}
/**
* Implementation of hook_page_title_settings().
*/
function comment_page_title_settings() {
return array(
'page_title_comment_reply' => array(
'label' => 'Comment Reply',
'scopes' => array('global', 'node'),
'description' => 'This pattern will be used for comment reply pages, where the reply is directly to a "node"',
),
'page_title_comment_child_reply' => array(
'label' => 'Comment Child Reply',
'scopes' => array('global', 'comment', 'node'),
'description' => 'This pattern with be used for comment reply pages where the reply is to an existing "comment" (eg a comment thread)',
),
);
}
......@@ -10,10 +10,10 @@
* Implementation of hook_page_title_alter().
*/
function forum_page_title_alter(&$title) {
$menu_item = menu_get_item();
// Check we're on a forum page and if there is a number to confirm it's a
// container or forum (rather than root).
if ( $menu_item = menu_get_item() &&
!strncmp($menu_item['path'], 'forum/%', 7) &&
if ( !strncmp($menu_item['path'], 'forum/%', 7) &&
($term = menu_get_object('taxonomy_term')) &&
variable_get('page_title_vocab_'. $term->vid .'_showfield', 0) &&
($forum_title = page_title_load_title($term->tid, 'term')) ) {
......@@ -43,3 +43,18 @@ function forum_page_title_pattern_alter(&$pattern, &$types) {
$types['vocabulary'] = taxonomy_vocabulary_load($forum_vid);
}
}
/**
* Implementation of hook_page_title_settings().
*/
function forum_page_title_settings() {
return array(
'page_title_forum_root_title' => array(
'label' => 'Forum Root',
'scopes' => array('global'),
'show field' => FALSE,
'description' => 'This pattern will be used on the forum root page (ie <code>/forum</code>)',
),
);
}
......@@ -61,3 +61,25 @@ function node_page_title_pattern_alter(&$pattern, &$types) {
$pattern = variable_get('page_title_type_'. $types['node']->type, '');
}
}
/**
* Implementation of hook_page_title_settings().
*/
function node_page_title_settings() {
$settings = array();
$types = node_type_get_types();
foreach ($types as $type) {
$settings['page_title_type_'. $type->type] = array(
'label' => 'Content Type - %type',
'label arguments' => array('%type' => $type->name),
'scopes' => array('global', 'node', 'term', 'vocabulary'),
'show field' => TRUE,
'description' => 'This pattern will be used for all %type node-type pages',
'description arguments' => array('%type' => $type->name),
);
}
return $settings;
}
......@@ -32,3 +32,36 @@ function page_title_page_title_pattern_alter(&$pattern, &$types) {
$pattern = variable_get('page_title_front', '[site:name] | [site:slogan]');
}
}
/**
* Implementation of hook_page_title_settings().
*/
function page_title_page_title_settings() {
return array(
'page_title_default' => array(
'label' => 'Default',
'scopes' => array('global'),
'required' => TRUE,
'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]',
),
'page_title_front' => array(
'label' => 'Fronpage',
'scopes' => array('global'),
'show field' => FALSE,
'description' => 'This pattern will be used for the site frontpage',
'weight' => -49,
'default' => '[site-name] | [site-slogan]',
),
'page_title_pager_pattern' => array(
'label' => 'Pager Suffix',
'scopes' => array('global'),
'show field' => FALSE,
'description' => 'This pattern will be appended to a page title for any given page with a pager on it',
'weight' => -48,
),
);
}
......@@ -34,3 +34,25 @@ function taxonomy_page_title_pattern_alter(&$pattern, &$types) {
$pattern = variable_get('page_title_vocab_'. $term->vid, '');
}
}
/**
* Implementation of hook_page_title_settings().
*/
function taxonomy_page_title_settings() {
$settings = array();
$vocabs = taxonomy_get_vocabularies();
foreach ($vocabs as $vocab) {
$settings['page_title_vocab_'. $vocab->vid] = array(
'label' => 'Vocabulary - %vocab_name',
'label arguments' => array('%vocab_name' => $vocab->name),
'scopes' => array('global', 'term', 'vocabulary'),
'show field' => TRUE,
'description' => 'This pattern will be used for all %vocab_name term pages',
'description arguments' => array('%vocab_name' => $vocab->name),
);
}
return $settings;
}
......@@ -28,3 +28,18 @@ function user_page_title_pattern_alter(&$pattern, &$types) {
$pattern = variable_get('page_title_user', '');
}
}
/**
* Implementation of hook_page_title_settings().
*/
function user_page_title_settings() {
return array(
'page_title_user' => array(
'label' => 'User Profile',
'scopes' => array('global', 'user'),
'show field' => TRUE,
'description' => 'This pattern will be used for a user profile page (eg <code>/user/1</code>)',
),
);
}
......@@ -15,161 +15,40 @@ function page_title_admin_settings() {
// Set the page title - the page is a local task now.
drupal_set_title(t('Page titles'));
// Define a default looking 'form element' for setting.
$showfield_form_element = array('#type' => 'checkbox', '#title_display' => 'invisible');
// Define a default looking 'form element' for setting.
$pattern_form_element = array(
'#type' => 'textfield',
'#size' => 60,
'#maxlength' => 255,
'#element_validate' => array('token_element_validate_token_context'),
'#token_types' => array(),
// Set the theme callback for the patterns section
$form['patterns'] = array(
'#theme' => 'page_title_admin_settings',
);
$all_settings = page_title_get_settings();
// Define the basic scope column values
$form['patterns']['scope'] = array(
'page_title_default' => array('#markup' => t('Global'),),
'page_title_front' => array('#markup' => t('Global'),),
'page_title_comment_reply' => array('#markup' => t('Node'), ),
'page_title_comment_child_reply' => array('#markup' => t('Node') .'<br />'. t('Comment'), ),
'page_title_pager_pattern' => array('#markup' => t('Global'), ),
'page_title_user' => array('#markup' => t('User'),),
);
// Define the 'default' token patterns
$form['patterns']['pattern'] = array(
//Define the default pattern - this is a "fallback" pattern.
'page_title_default' => array(
'#title' => t('Default'),
'#default_value' => variable_get('page_title_default', '[current-page:page-title] | [site:name]'),
'#description' => t('This pattern will be used as a <em>fallback</em> (ie, when no other pattern is defined)'),
'#required' => TRUE,
) + $pattern_form_element,
// Define the frontpage pattern. This is use on <front>
'page_title_front' => array(
'#title' => t('Frontpage'),
'#default_value' => variable_get('page_title_front', '[site:name] | [site:slogan]'),
'#description' => t('This pattern will be used for the site frontpage'),
) + $pattern_form_element,
// Define the pager pattern. This is appended to any page requests containing 'page=[0-9]+' in the query string
'page_title_pager_pattern' => array(
'#title' => t('Pager Suffix'),
'#default_value' => variable_get('page_title_pager_pattern', ''),
'#description' => t('This pattern will be appended to a page title for any given page with a pager on it'),
) + $pattern_form_element,
// Define the comment reply pattern. This is used for a root comment reply (ie comment/[0-9]+).
'page_title_comment_reply' => array(
'#title' => t('Comment Reply'),
'#default_value' => variable_get('page_title_comment_reply', ''),
'#description' => t('This pattern will be used for comment reply pages, where the reply is directly to a "node"'),
'#token_types' => array('node'),
) + $pattern_form_element,
// Define the comment reply to comment pattern. This is used for a reply to a comment (ie comment/[0-9]+/[0-9]+).
'page_title_comment_child_reply' => array(
'#title' => t('Comment Child Reply'),
'#default_value' => variable_get('page_title_comment_child_reply', ''),
'#description' => t('This pattern with be used for comment reply pages where the reply is to an existing "comment" (eg a comment thread)'),
'#token_types' => array('comment', 'node'),
) + $pattern_form_element,
// Define the user profile page pattern. This is used on any 'user/[0-9]' pages
'page_title_user' => array(
'#title' => t('User Profile'),
'#default_value' => variable_get('page_title_user', ''),
'#description' => t('This pattern will be used for any user profile pages'),
'#token_types' => array('user'),
) + $pattern_form_element,
);
// Define the "showfield" checkbox for the user profile page
$form['patterns']['showfield']['page_title_user_showfield'] = array(
'#title' => t('Show page title field on User Profile edit form'),
'#default_value' => variable_get('page_title_user_showfield', 0),
) + $showfield_form_element;
// Definate the patterns per-node-type
$types = node_type_get_types();
foreach ($types as $type) {
// Define the node-type key
$key = 'page_title_type_'. $type->type;
// Pattern entry
foreach ($all_settings as $key => $settings) {
$form['patterns']['pattern'][$key] = array(
'#title' => t('Content Type - %type', array('%type' => $type->name)),
'#default_value' => variable_get($key, ''),
'#description' => t('This pattern will be used for all %type node-type pages', array('%type' => $type->name)),
'#token_types' => array('node', 'term'),
) + $pattern_form_element;
$form['patterns']['showfield'][$key .'_showfield'] = array(
'#title' => t('Show page title field on the %type edit form', array('%type' => $type->name)),
'#default_value' => variable_get($key .'_showfield', 0),
) + $showfield_form_element;
$form['patterns']['scope'][$key] = array('#markup' => t('Node') . ', ' . t('Taxonomy'),);
}
// Definate the patterns per-vocab-type - if Taxonomy Module is enabled
if (module_exists('taxonomy')) {
$vocabs = taxonomy_get_vocabularies();
foreach ($vocabs as $vocab) {
// Define the vocab key
$key = 'page_title_vocab_'. $vocab->vid;
'#title' => t($settings['label'], $settings['label arguments']),
'#default_value' => variable_get($key, $settings['default']),
'#required' => $settings['required'],
'#description' => t($settings['description'], $settings['description arguments']),
'#weight' => $settings['weight'],
'#token_types' => $settings['scopes'],
'#element_validate' => array('token_element_validate'),
'#type' => 'textfield',
'#size' => 30,
);
// Pattern entry
$form['patterns']['pattern'][$key] = array(
'#title' => t('Vocabulary - %vocab_name', array('%vocab_name' => $vocab->name)),
'#default_value' => variable_get($key, ''),
'#description' => t('This pattern will be used for all %title term pages', array('%title' => $vocab->name)),
'#token_types' => array('term'),
) + $pattern_form_element;
$form['patterns']['scope'][$key] = array(
'#markup' => implode('<br />', array_map('_page_title_scope_t', $settings['scopes'])),
);
if ($settings['show field']) {
$form['patterns']['showfield'][$key .'_showfield'] = array(
'#title' => t('Show page title field on the %vocab_name term edit form', array('%vocab_name' => $vocab->name)),
'#type' => 'checkbox',
'#default_value' => variable_get($key .'_showfield', 0),
) + $showfield_form_element;
$form['patterns']['scope'][$key] = array('#markup' => t('Taxonomy'));
);
}
}
// Add the blog homepage pattern field
if (module_exists('blog')) {
$key = 'page_title_blog';
$form['patterns']['pattern'][$key] = array(
'#title' => t('Blog Homepage'),
'#default_value' => variable_get($key, ''),
'#token_types' => array('user'),
) + $pattern_form_element;
$form['patterns']['scope'][$key] = array('#markup' => t('User'));
}
// Add the forum root pattern field
if (module_exists('forum')) {
$form['patterns']['pattern']['page_title_forum_root_title'] = array(
'#title' => t('Forum Root'),
'#default_value' => variable_get('page_title_forum_root_title', ''),
'#description' => t('This pattern will be used on the forum root page (ie, <code>/forum</code>)'),
'#token_types' => array('vocabulary'),
) + $pattern_form_element;
$form['patterns']['scope']['page_title_forum_root_title'] = array('#markup' => t('Vocabulary'));
}
// Add the token help to a collapsed fieldset at the end of the configuration page.
$form['token_help'] = array(
'#type' => 'fieldset',
......@@ -182,38 +61,12 @@ function page_title_admin_settings() {
'#token_types' => array('node', 'comment', 'term', 'vocabulary', 'user'),
);
$form = system_settings_form($form);
unset($form['#theme']);
return $form;
}
function theme_page_title_admin_settings($variables) {
$form = $variables['form'];
$rows = array();
foreach (element_children($form['patterns']['pattern']) as $key) {
$title = array(
'#markup' => $form['patterns']['pattern'][$key]['#title'],
'#required' => $form['patterns']['pattern'][$key]['#required'],
);
unset($form['patterns']['pattern'][$key]['#title']);
$row = array(
array('data' => render($title), 'class' => 'page-type'),
array('data' => render($form['patterns']['scope'][$key]), 'class' => 'scope'),
);
if (isset($form['patterns']['showfield'][$key .'_showfield'])) {
$row[] = array('data' => render($form['patterns']['pattern'][$key]), 'class' => 'pattern');
$row[] = array('data' => render($form['patterns']['showfield'][$key .'_showfield']), 'class' => 'showfield');
}
else {
$row[] = array('data' => render($form['patterns']['pattern'][$key]), 'colspan' => 2, 'class' => 'pattern');
}
$rows[] = $row;
}
$output = theme('table', array('header' => array(t('Page Type'), t('Token Scope'), t('Pattern'), t('Show Field')), 'rows' => $rows));
$output .= drupal_render_children($form);
return $output;
function _page_title_scope_t($item) {
return t(ucfirst($item));
}
......@@ -37,6 +37,62 @@ function page_title_help($path, $arg) {
}
/**
* Implementation of hook_requirements().
*/
function page_title_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// Are we on an old version?
if (!page_title_is_up_to_date()) {
$requirements['page_title_version'] = array(
'title' => t('Page title version'),
'value' => t('Out of date'),
'description' => t('The Page Title module must be updated. You should run the !link immediately.', array('!link' => l(t('database update script'), 'update.php'))),
'severity' => REQUIREMENT_ERROR,
);
}
// Nope - we're on the latest version
else {
// Does the old table exist (it is left after the upgrade in case an admin wants to check the upgrade went ok)
if (db_table_exists('page_title_old')) {
$requirements['upgrade_table'] = array(
'title' => t('Page Title upgrade table present'),
'value' => '',
'description' => t('The Page Title upgrade table (<code>page_title_old</code>) is present. You can remove it !link', array(
'!link' => l(t('using this script'), 'admin/settings/page-title/drop-old-table'),
)),
'severity' => REQUIREMENT_WARNING,
);
}
// If the page title module exists, check it has the right columns - there are reports of upgrade issues.
// If the table doesn't exists, reinstall the module!
if (!db_table_exists('page_title') || db_field_exists('page_title', 'nid')) {
$requirements['page_title_version'] = array(
'title' => t('Page title version'),
'value' => t('Incorrect Schema'),
'description' => t('It appears Drupal thinks the module is up to date, however the database schema is incorrect. Please uninstall and reinstall the module.'),
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Everything seems ok...
$rows = db_query('SELECT COUNT(*) FROM {page_title}')->fetchField();
$requirements['page_title_version'] = array(
'title' => t('Page title version'),
'value' => t('Enabled (<code>page_title</code> table contains !rows)', array('!rows' => format_plural($rows, '1 row', '@count rows'))),
'severity' => REQUIREMENT_OK,
);
}
}
}
return $requirements;
}
/**
* Implement hook_perm().
*/
......@@ -80,6 +136,7 @@ function page_title_menu() {
function page_title_theme() {
return array(
'page_title_admin_settings' => array(
'template' => 'page_title-admin-settings-form',
'render element' => 'form',
'file' => 'page_title.admin.inc',
),
......@@ -640,6 +697,53 @@ function page_title_views_plugins() {
}
/**
* Get the Page Title Setttings
*/
function page_title_get_settings() {
// Get from the cache, if present
if ($cache = cache_get('page_title:settings')) {
return $cache->data;
}
// Get the settings from hoko_page_title_settings().
$settings = module_invoke_all('page_title_settings');
// For each setting, apply a "default" mask (this makes it easier to use
// later as we can assume presence).
foreach ($settings as $k => $v) {
$settings[$k] = (array) $v + array(
'label' => '',
'label arguments' => array(),
'required' => FALSE,
'show field' => FALSE,
'description' => '',
'description arguments' => array(),
'weight' => 0,
'default' => '',
);
}
// Now sort
uasort($settings, '_page_title_settings_sort');
// Cache this so we dont have to do this EVERY time
cache_set('page_title:settings', $settings);
return $settings;
}
/**
* Internal function for sorting the page title settings array.
*/
function _page_title_settings_sort($a, $b) {
// Sort by weight and, failing that, label alphabetical.
return $a['weight'] < $b['weight'] ? -1 : ($a['weight'] > $b['weight'] ? 1 : ($a['label'] < $b['label'] ? -1 : 1));
}
/**
* Get a list of modules that support the current Page Title API.
*/
......@@ -686,3 +790,11 @@ function forum_page_title_api() { return page_title_page_title_api(); }
function user_page_title_api() { return page_title_page_title_api(); }
function blog_page_title_api() { return page_title_page_title_api(); }
function views_page_title_api() { return page_title_page_title_api(); }
/**
* Internal function for checking if Page Title is ok to run
*/
function page_title_is_up_to_date() {
return drupal_get_installed_schema_version('page_title') >= max(drupal_get_schema_versions('page_title'));
}
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