Commit 6b770dd0 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Generalized bundle settings and form handling. Yay for recycling and reducing code!

parent 466ea41c
......@@ -129,13 +129,11 @@ function xmlsitemap_settings_form() {
$form[$entity]['#access'] = (bool) element_get_visible_children($form[$entity]);
}
$form['#pre_render'][] = 'vertical_tabs_form_pre_render';
$form['#validate'][] = 'xmlsitemap_settings_form_validate';
$form['#submit'][] = 'xmlsitemap_settings_form_submit';
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
$form = system_settings_form($form);
$form['actions']['#weight'] = 100;
return $form;
}
......@@ -277,17 +275,6 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
$rows = array();
$totals = array('total' => 0, 'indexed' => 0, 'visible' => 0);
foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
if (isset($bundle_info['admin'])) {
$bundle_info['admin'] += array(
'access callback' => 'user_access',
'access arguments' => array(),
'access' => FALSE,
);
if ($bundle_info['admin']['access callback']) {
$bundle_info['admin']['access'] = call_user_func_array($bundle_info['admin']['access callback'], $bundle_info['admin']['access arguments']);
}
}
// Fetch current per-bundle link total and indexed counts.
$status = xmlsitemap_get_link_type_indexed_status($entity, $bundle);
$totals['total'] += $status['total'];
......@@ -295,7 +282,7 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
$totals['visible'] += $status['visible'];
$row = array();
if (!empty($bundle_info['admin']['access'])) {
if (xmlsitemap_can_admin_bundle($bundle_info) && !empty($bundle_info['admin']['real path'])) {
$row[] = l($bundle_info['label'], $bundle_info['admin']['real path'], array('query' => drupal_get_destination()));
}
else {
......@@ -348,35 +335,83 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
/**
* Add the link type XML sitemap options to the link type's form.
*
* @todo Abstract the submission and link updating for this submit?
* Caller is responsible for ensuring xmlsitemap_link_bundle_settings_save()
* is called during submission.
*/
function xmlsitemap_add_form_type_options(&$form, $module, $options) {
$form['xmlsitemap'] = array(
function xmlsitemap_add_link_bundle_settings(array &$form, array $form_state, $entity, $bundle) {
xmlsitemap_link_bundle_settings_form($form, $form_state, $entity, $bundle, FALSE);
// Make the base element a fieldset.
$form['xmlsitemap'] += array(
'#type' => 'fieldset',
'#title' => t('XML sitemap'),
'#description' => t('Changing these type settings will affect any items of this type that have either inclusion or priority set to default.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#access' => user_access('administer xmlsitemap'),
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
'vertical-tabs' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.js',
),
),
);
// Hack to remove fieldset summary if Vertical tabs is not enabled.
if (!isset($form['additional_settings'])) {
unset($form['xmlsitemap']['#attached']['js']['vertical-tabs']);
}
}
function xmlsitemap_link_bundle_settings_form(array &$form, array $form_state, $entity, $bundle, $buttons = TRUE) {
$settings = xmlsitemap_link_bundle_settings_load($entity, $bundle);
$form['xmlsitemap'] = array(
'#tree' => TRUE,
'#entity' => $entity,
'#bundle' => $bundle,
);
$form['xmlsitemap']['description'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
'#markup' => t('Changing these type settings will affect any items of this type that have either inclusion or priority set to default.'),
);
$form['xmlsitemap']['xmlsitemap_' . $module . '_status'] = array(
$form['xmlsitemap']['status'] = array(
'#type' => 'select',
'#title' => t('Inclusion'),
'#options' => xmlsitemap_get_status_options(),
'#default_value' => $options['status'],
'#default_value' => $settings['status'],
);
$form['xmlsitemap']['xmlsitemap_' . $module . '_priority'] = array(
$form['xmlsitemap']['priority'] = array(
'#type' => 'select',
'#title' => t('Default priority'),
'#options' => xmlsitemap_get_priority_options(),
'#default_value' => $options['priority'],
'#default_value' => $settings['priority'],
'#states' => array(
'invisible' => array(
'select[name="xmlsitemap_' . $module . '_status"]' => array('value' => '0'),
'select[name="xmlsitemap[status]"]' => array('value' => '0'),
),
),
);
if ($buttons) {
$form['actions'] = array(
'#type' => 'container',
);
$form['actions']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
}
return $form;
}
function xmlsitemap_link_bundle_settings_form_submit($form, $form_state) {
$entity = $form['xmlsitemap']['#entity'];
$bundle = $form['xmlsitemap']['#bundle'];
$info = xmlsitemap_get_link_info($entity);
xmlsitemap_link_bundle_settings_save($entity, $bundle, $form_state['values']['xmlsitemap']);
drupal_set_message(t('Settings for the @bundle-label %bundle have been saved.', array('@bundle-label' => drupal_strtolower($info['bundle label']), '%bundle' => $info['bundles'][$bundle]['label'])));
}
/**
......@@ -385,6 +420,8 @@ function xmlsitemap_add_form_type_options(&$form, $module, $options) {
* @todo Add changefreq overridability.
*/
function xmlsitemap_add_form_link_options(&$form, $link) {
$info = xmlsitemap_get_link_info($link['type']);
$form['xmlsitemap'] = array(
'#type' => 'fieldset',
'#tree' => TRUE,
......@@ -400,6 +437,20 @@ function xmlsitemap_add_form_link_options(&$form, $link) {
),
);
// Hack to remove fieldset summary if Vertical tabs is not enabled.
if (!isset($form['additional_settings'])) {
unset($form['xmlsitemap']['#attached']['js']['vertical-tabs']);
}
$bundle_info = $info['bundles'][$link['subtype']];
if (xmlsitemap_can_admin_bundle($bundle_info) && !empty($bundle_info['admin']['real path'])) {
$form['xmlsitemap']['description'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
'#markup' => t('The default XML sitemap settings for this @bundle can be changed <a href="@link-type">here</a>.', array('@bundle' => drupal_strtolower($info['bundle label']), '@link-type' => url($bundle_info['admin']['real path'], array('query' => drupal_get_destination())))),
);
}
// Show a warning if the link is not accessible and will not be included in
// the sitemap.
if (!$link['access']) {
......
......@@ -793,7 +793,7 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
foreach ($info['bundles'] as $bundle_key => $bundle) {
if (!isset($bundle['xmlsitemap'])) {
// Remove any un-supported entity bundles.
unset($link_info[$key]['bundles'][$bundle_key]);
//unset($link_info[$key]['bundles'][$bundle_key]);
}
}
}
......@@ -808,6 +808,12 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
if (!isset($info['xmlsitemap']['rebuild callback']) && !empty($info['base table']) && !empty($info['object keys']['id']) && !empty($info['xmlsitemap']['process callback'])) {
$info['xmlsitemap']['rebuild callback'] = 'xmlsitemap_rebuild_batch_fetch';
}
foreach ($info['bundles'] as $bundle => &$bundle_info) {
$bundle_info += array(
'xmlsitemap' => array(),
);
$bundle_info['xmlsitemap'] += xmlsitemap_link_bundle_settings_load($key, $bundle);
}
}
drupal_alter('xmlsitemap_link_info', $link_info);
ksort($link_info);
......@@ -941,7 +947,9 @@ function xmlsitemap_get_link_type_enabled_bundles($entity_type) {
$bundles = array();
$info = xmlsitemap_get_link_info($entity_type);
foreach ($info['bundles'] as $bundle => $bundle_info) {
if (!empty($bundle_info['xmlsitemap']['status'])) {
$settings = xmlsitemap_link_bundle_settings_load($entity_type, $bundle);
if (!empty($settings['status'])) {
//if (!empty($bundle_info['xmlsitemap']['status'])) {
$bundles[] = $bundle;
}
}
......@@ -971,3 +979,48 @@ function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
return $status;
}
function xmlsitemap_link_bundle_settings_save($entity, $bundle, array $settings, $update_links = TRUE) {
if ($update_links) {
$old_settings = xmlsitemap_link_bundle_settings_load($entity, $bundle);
if ($settings['status'] != $old_settings['status']) {
xmlsitemap_update_links(array('status' => $settings['status']), array('type' => $entity, 'subtype' => $bundle, 'status_override' => 0));
}
if ($settings['priority'] != $old_settings['priority']) {
xmlsitemap_update_links(array('priority' => $settings['priority']), array('type' => $entity, 'subtype' => $bundle, 'priority_override' => 0));
}
}
variable_set("xmlsitemap_settings_{$entity}_{$bundle}", $settings);
cache_clear_all('xmlsitemap:link_info:', 'cache', TRUE);
//xmlsitemap_get_link_info(NULL, TRUE);
}
function xmlsitemap_link_bundle_settings_load($entity, $bundle) {
$settings = variable_get("xmlsitemap_settings_{$entity}_{$bundle}", array());
$settings += array('status' => 0, 'priority' => 0.5);
return $settings;
}
function xmlsitemap_link_bundle_delete($entity, $bundle, $delete_links = TRUE) {
variable_del("xmlsitemap_settings_{$entity}_{$bundle}");
if ($delete_links) {
xmlsitemap_link_delete_multiple(array('type' => $entity, 'subtype' => $bundle));
}
cache_clear_all('xmlsitemap:link_info:', 'cache', TRUE);
//xmlsitemap_get_link_info(NULL, TRUE);
}
function xmlsitemap_can_admin_bundle(array $bundle_info) {
if (isset($bundle_info['admin'])) {
$bundle_info['admin'] += array(
'access callback' => 'user_access',
'access arguments' => array(),
);
if (!empty($bundle_info['admin']['access callback'])) {
return call_user_func_array($bundle_info['admin']['access callback'], $bundle_info['admin']['access arguments']);
}
}
return FALSE;
}
......@@ -10,11 +10,11 @@
* Implements hook_uninstall().
*/
function xmlsitemap_menu_uninstall() {
// Remove variables.
drupal_load('module', 'xmlsitemap_menu');
$variables = array_keys(xmlsitemap_menu_variables());
foreach ($variables as $variable) {
variable_del($variable);
drupal_load('module', 'menu');
drupal_load('module', 'xmlsitemap');
$menus = array_keys(menu_get_menus());
foreach ($menus as $menu) {
xmlsitemap_link_bundle_delete('menu', $menu);
}
}
......@@ -67,3 +67,23 @@ function xmlsitemap_menu_update_7() {
}
}
}
/**
* Cleanup variables.
*/
function xmlsitemap_menu_update_6200() {
drupal_load('module', 'menu');
$menus = array_keys(menu_get_menus());
foreach ($menus as $menu) {
$settings = array(
'status' => variable_get('xmlsitemap_menu_status_' . $menu, 0),
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu, 0.5),
);
variable_set('xmlsitemap_settings_menu_' . $menu, $settings);
variable_del('xmlsitemap_menu_status_' . $menu);
variable_del('xmlsitemap_menu_priority_' . $menu);
variable_del('xmlsitemap_menu_calculate_priority_' . $menu);
}
variable_del('xmlsitemap_menu_menus');
variable_del('xmlsitemap_menu_calculate_priority');
}
......@@ -25,10 +25,6 @@ function xmlsitemap_menu_xmlsitemap_link_info() {
'real path' => 'admin/structure/menu/manage/' . $menu . '/edit',
'access arguments' => array('administer menu'),
),
'xmlsitemap' => array(
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu, 0.5),
'status' => variable_get('xmlsitemap_menu_status_' . $menu, 0),
),
);
}
return $types;
......@@ -53,7 +49,7 @@ function xmlsitemap_menu_cron() {
function xmlsitemap_menu_xmlsitemap_index_links($limit) {
if ($menus = xmlsitemap_get_link_type_enabled_bundles('menu')) {
$sql = "SELECT ml.mlid FROM {menu_links} ml LEFT JOIN {xmlsitemap} x ON x.type = 'menu' AND ml.mlid = x.id WHERE x.id IS NULL AND ml.menu_name IN (:menus) ORDER BY ml.mlid DESC";
$mlids = db_query_range($sql, 0, $limit, array(':menus' => $menus));
$mlids = db_query_range($sql, 0, $limit, array(':menus' => $menus))->fetchCol();
xmlsitemap_menu_xmlsitemap_process_menu_links($mlids);
}
}
......@@ -82,80 +78,53 @@ function xmlsitemap_menu_xmlsitemap_process_menu_links(array $mlids) {
* Implements hook_form_FORM_ID_alter().
*
* @see menu_edit_menu()
* @see xmlsitemap_menu_menu_edit_menu_submit()
* @see xmlsitemap_add_link_bundle_settings()
*/
function xmlsitemap_menu_form_menu_edit_menu_alter(&$form, $form_state) {
$menu = isset($form['menu_name']['#value']) ? $form['menu_name']['#value'] : '';
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
$options = array(
'status' => variable_get('xmlsitemap_menu_status_' . $menu, 0),
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu, 0.5),
);
xmlsitemap_add_form_type_options($form, 'menu', $options);
// @todo Enable this feature:
//$form['xmlsitemap']['xmlsitemap_menu_calculate_priority'] = array(
// '#type' => 'checkbox',
// '#title' => t('Calculate priority based on menu item depth and weight.'),
// '#default_value' => variable_get('xmlsitemap_menu_calculate_priority_' . $menu, FALSE),
//);
xmlsitemap_add_link_bundle_settings($form, $form_state, 'menu', $menu);
$form['#submit'][] = 'xmlsitemap_menu_menu_edit_menu_submit';
}
/**
* Form submit handler; update settings when a menu is saved.
*/
function xmlsitemap_menu_menu_edit_menu_submit($form, $form_state) {
$menu = $form_state['values']['menu_name'];
$new_priority = $form_state['values']['xmlsitemap_menu_priority'];
$new_status = $form_state['values']['xmlsitemap_menu_status'];
if ($new_status != variable_get('xmlsitemap_menu_status_' . $menu, 0)) {
xmlsitemap_update_links(array('status' => $new_status), array('type' => 'menu', 'subtype' => $menu, 'status_override' => 0));
}
if ($new_priority != variable_get('xmlsitemap_menu_priority_' . $menu, 0.5)) {
xmlsitemap_update_links(array('priority' => $new_priority), array('type' => 'menu', 'subtype' => $menu, 'priority_override' => 0));
}
}
//function xmlsitemap_menu_form_menu_overview_form_alter(&$form, $form_state) {
// $form['#submit'][] = 'xmlsitemap_menu_menu_overview_form_submit';
//}
//
//function xmlsitemap_menu_menu_overview_form_submit($form, $form_state) {
// $mlids = array();
// foreach (element_children($form) as $mlid) {
// if (isset($form[$mlid]['#item'])) {
// $menu_item = menu_link_load($form[$mlid]['#item']['mlid'], TRUE);
// xmlsitemap_menu_item_update($menu_item);
// $mlids[] = $form[$mlid]['#item']['mlid'];
// }
// }
// xmlsitemap_menu_xmlsitemap_process_menu_links($mlids);
//}
/**
* Implements hook_menu_insert().
*/
function xmlsitemap_menu_menu_insert(array $menu) {
variable_set('xmlsitemap_menu_priority_' . $menu['menu_name'], $menu['xmlsitemap_menu_priority']);
variable_set('xmlsitemap_menu_status_' . $menu['menu_name'], $menu['xmlsitemap_menu_status']);
if (isset($menu['xmlsitemap'])) {
xmlsitemap_link_bundle_settings_save('menu', $menu['menu_name'], $menu['xmlsitemap']);
}
}
/**
* Implements hook_menu_update().
*/
function xmlsitemap_menu_menu_update(array $menu) {
variable_set('xmlsitemap_menu_priority_' . $menu['menu_name'], $menu['xmlsitemap_menu_priority']);
variable_set('xmlsitemap_menu_status_' . $menu['menu_name'], $menu['xmlsitemap_menu_status']);
if (isset($menu['xmlsitemap'])) {
xmlsitemap_link_bundle_settings_save('menu', $menu['menu_name'], $menu['xmlsitemap']);
}
}
/**
* Implements hook_menu_delete().
*/
function xmlsitemap_menu_menu_delete(array $menu) {
xmlsitemap_link_delete_multiple(array('type' => 'menu', 'subtype' => $menu['menu_name']));
variable_del('xmlsitemap_menu_status_' . $menu['menu_name']);
variable_del('xmlsitemap_menu_priority_ ' . $menu['menu_name']);
xmlsitemap_link_bundle_delete('menu', $menu['menu_name']);
}
/**
......@@ -193,15 +162,17 @@ function xmlsitemap_menu_create_link(array $menu_item) {
}
}
$settings = xmlsitemap_link_bundle_settings_load('menu', $menu_item['menu_name']);
$menu_item['xmlsitemap'] += array(
'type' => 'menu',
'id' => $menu_item['mlid'],
'loc' => $menu_item['link_path'],
'status' => variable_get('xmlsitemap_menu_status_' . $menu_item['menu_name'], 0),
'status_default' => variable_get('xmlsitemap_menu_status_' . $menu_item['menu_name'], 0),
'status' => $settings['status'],
'status_default' => $settings['status'],
'status_override' => 0,
'priority' => variable_get('xmlsitemap_menu_priority_' . $menu_item['menu_name'], 0.5),
'priority_default' => variable_get('xmlsitemap_menu_priority_' . $menu_item['menu_name'], 0.5),
'priority' => $settings['priority'],
'priority_default' => $settings['priority'],
'priority_override' => 0,
);
......@@ -226,16 +197,13 @@ function xmlsitemap_menu_calculate_priority(array $menu_item) {
* Internal default variables for template_var().
*/
function xmlsitemap_menu_variables() {
$defaults = array(
// Deprecated variables set to NULL so they are still removed on uninstall.
'xmlsitemap_menu_menus' => NULL,
'xmlsitemap_menu_calculate_priority' => NULL,
);
$defaults = array();
$menus = array_keys(menu_get_menus());
foreach ($menus as $menu) {
$defaults['xmlsitemap_menu_status_' . $menu] = 0;
$defaults['xmlsitemap_menu_priority_' . $menu] = 0.5;
$defaults['xmlsitemap_menu_calculate_priority_' . $menu] = FALSE;
$defaults['xmlsitemap_settings_menu_' . $menu] = array(
'status' => 0,
'priority' => 0.5,
);
}
return $defaults;
}
......@@ -10,11 +10,11 @@
* Implements hook_uninstall().
*/
function xmlsitemap_node_uninstall() {
// Remove variables.
drupal_load('module', 'xmlsitemap_node');
$variables = array_keys(xmlsitemap_node_variables());
foreach ($variables as $variable) {
variable_del($variable);
drupal_load('module', 'node');
drupal_load('module', 'xmlsitemap');
$node_types = array_keys(node_type_get_names());
foreach ($node_types as $node_type) {
xmlsitemap_link_bundle_delete('node', $node_type);
}
}
......@@ -31,7 +31,7 @@ function xmlsitemap_node_update_1() {
}
function xmlsitemap_node_update_2() {
$node_types = array_keys(node_get_types('names'));
$node_types = array_keys(node_type_get_names());
foreach ($node_types as $node_type) {
if (variable_get('xmlsitemap_node_priority_' . $node_type, 'default') === 'default') {
variable_set('xmlsitemap_node_priority_' . $node_type, 0.5);
......@@ -60,3 +60,22 @@ function xmlsitemap_node_update_4() {
function xmlsitemap_node_update_5() {
db_query("UPDATE {xmlsitemap} SET language = (SELECT {node}.language FROM {node} WHERE {node}.nid = {xmlsitemap}.id) WHERE {xmlsitemap}.type = 'node'");
}
/**
* Cleanup variables.
*/
function xmlsitemap_node_update_6200() {
drupal_load('module', 'node');
$node_types = array_keys(node_type_get_names());
foreach ($node_types as $node_type) {
$settings = array(
'status' => variable_get('xmlsitemap_node_status_' . $node_type, 0),
'priority' => variable_get('xmlsitemap_node_priority_' . $node_type, 0.5),
);
variable_set('xmlsitemap_settings_node_' . $node_type, $settings);
variable_del('xmlsitemap_node_status_' . $node_type);
variable_del('xmlsitemap_node_priority_' . $node_type);
variable_del('xmlsitemap_node_update_' . $node_type);
}
return array();
}
// $Id$
(function ($) {
Drupal.behaviors.xmlsitemapFieldsetSummaries = {
attach: function (context) {
$('fieldset#edit-xmlsitemap', context).setSummary(function (context) {
var vals = [];
// Inclusion select field.
var status = $('#edit-xmlsitemap-node-status option:selected').text();
vals.push(Drupal.t('Inclusion: @value', { '@value': status }));
// Priority select field.
var priority = $('#edit-xmlsitemap-node-priority option:selected').text();
vals.push(Drupal.t('Priority: @value', { '@value': priority }));
return vals.join('<br />');
});
}
};
})(jQuery);
......@@ -10,12 +10,6 @@ function xmlsitemap_node_entity_info_alter(&$entity_info) {
$entity_info['node']['xmlsitemap'] = array(
'process callback' => 'xmlsitemap_node_xmlsitemap_process_node_links',
);
foreach (node_type_get_names() as $type => $name) {
$entity_info['node']['bundles'][$type]['xmlsitemap'] = array(
'priority' => variable_get('xmlsitemap_node_priority_' . $type, 0.5),
'status' => variable_get('xmlsitemap_node_status_' . $type, 0),
);
}
}
/**
......@@ -103,13 +97,25 @@ function xmlsitemap_node_comment_delete(stdClass $comment) {
xmlsitemap_node_comment_update($comment);
}
/**
* Implements_hook_node_type_update().
*/
function xmlsitemap_node_node_type_update(stdClass $info) {
// Cannot perform xmlsitemap_link_bundle_settings_save() here since
// node_type_form_submit() strips all non-essential data from $info.
if (!empty($info->old_type) && $info->old_type != $info->type) {
$setting = variable_get('xmlsitemap_settings_node_'. $info->old_type, array());
variable_del('xmlsitemap_settings_node_'. $info->old_type);
variable_set('xmlsitemap_settings_node_'. $info->type, $setting);
xmlsitemap_update_links(array('subtype' => $info->type), array('type' => 'node', 'subtype' => $info->old_type));
}
}
/**
* Implements hook_node_type_delete().
*/
function xmlsitemap_node_node_type_delete($info) {
variable_del('xmlsitemap_node_status_' . $info->type);
variable_del('xmlsitemap_node_priority_' . $info->type);
//xmlsitemap_link_delete_multiple(array('type' => 'node', 'subtype' => $info->type));
function xmlsitemap_node_node_type_delete(stdClass $info) {
xmlsitemap_link_bundle_delete('node', $info->type);
}
/**
......@@ -135,39 +141,25 @@ function xmlsitemap_node_field_extra_fields() {
* Implements hook_form_FORM_ID_alter().
*
* @see node_type_form()
* @see xmlsitemap_add_form_type_options()
* @see xmlsitemap_add_link_bundle_settings()
*/
function xmlsitemap_node_form_node_type_form_alter(&$form, $form_state) {
$node_type = isset($form['#node_type']->type) ? $form['#node_type']->type : '';
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
$options = array(
'status' => variable_get('xmlsitemap_node_status_' . $node_type, 0),
'priority' => variable_get('xmlsitemap_node_priority_' . $node_type, 0.5),
);
xmlsitemap_add_form_type_options($form, 'node', $options);
$form['xmlsitemap']['#attached']['js']['vertical-tabs'] = drupal_get_path('module', 'xmlsitemap_node') . '/xmlsitemap_node.js';
xmlsitemap_add_link_bundle_settings($form, $form_state, 'node', $node_type);
// Add our submit handler before node_type_form_submit() so we can compare
// the old and new values.
array_unshift($form['#submit'], 'xmlsitemap_node_type_form_submit');
}
function xmlsitemap_node_type_form_submit($form, $form_state) {
function xmlsitemap_node_type_form_submit($form, &$form_state) {
$node_type = $form_state['values']['old_type'];
$new_status = $form_state['values']['xmlsitemap_node_status'];
$new_priority = $form_state['values']['xmlsitemap_node_priority'];
$new_type = $form_state['values']['type'];
xmlsitemap_link_bundle_settings_save('node', $node_type, $form_state['values']['xmlsitemap']);
if ($new_status != variable_get('xmlsitemap_node_status_' . $node_type, 0)) {
xmlsitemap_update_links(array('status' => $new_status), array('type' => 'node', 'subtype' => $node_type, 'status_override' => 0));
}
if ($new_priority != variable_get('xmlsitemap_node_priority_' . $node_type, 0.5)) {
xmlsitemap_update_links(array('priority' => $new_priority), array('type' => 'node', 'subtype' => $node_type, 'priority_override' => 0));
}
if ($node_type != $new_type) {
xmlsitemap_update_links(array('subtype' => $new_type), array('type' => 'node', 'subtype' => $node_type));
}
// Do not allow node_type_form_submit() to run variable_set() on this.
unset($form_state['values']['xmlsitemap']);
}
/**
......@@ -192,9 +184,6 @@ function xmlsitemap_node_form_alter(&$form, $form_state, $form_id) {
$form['xmlsitemap']['#access'] |= user_access('administer nodes');
$form['xmlsitemap']['#weight'] = 30;
if (user_access('administer content types')) {
$form['xmlsitemap']['#description'] = t('The default XML sitemap settings for this content type can be changed <a href="@link-type">here</a>.', array('@link-type' => url('admin/structure/types/manage/' . str_replace('_', '-', $node->type), array('query' => drupal_get_destination()))));
}
}
}
......@@ -232,16 +221,18 @@ function xmlsitemap_node_create_link(&$node) {
}
}
$settings = xmlsitemap_link_bundle_settings_load('node', $node->type);
$node->xmlsitemap += array(
'type' => 'node',
'id' => $node->nid,
'subtype' => $node->type,
'loc' => 'node/'. $node->nid,
'status' => variable_get('xmlsitemap_node_status_' . $node->type, 0),
'status_default' => variable_get('xmlsitemap_node_status_' . $node->type, 0),
'status' => $settings['status'],
'status_default' => $settings['status'],
'status_override' => 0,
'priority' => variable_get('xmlsitemap_node_priority_' . $node->type, 0.5),
'priority_default' => variable_get('xmlsitemap_node_priority_' . $node->type, 0.5),
'priority' => $settings['priority'],
'priority_default' => $settings['priority'],
'priority_override' => 0,
);
......@@ -270,10 +261,10 @@ function xmlsitemap_node_variables() {
$defaults = array();
$node_types = array_keys(node_type_get_names());
foreach ($node_types as $node_type) {
$defaults['xmlsitemap_node_priority_' . $node_type] = 0.5;
$defaults['xmlsitemap_node_status_' . $node_type] = 0;
// @todo Remove the variable.
$defaults['xmlsitemap_node_update_' . $node_type] = NULL;
$defaults['xmlsitemap_settings_node_' . $node_type] = array(
'status' => 0,
'priority' => 0.5,
);
}
return $defaults;
}
......@@ -15,7 +15,7 @@ class XMLSitemapNodeTestHelper extends XMLSitemapTestHelper {
parent::setUp('xmlsitemap', 'xmlsitemap_node', 'comment');
$this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access', 'administer content types', 'administer xmlsitemap'));
$this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content', 'view own unpublished content'));
variable_set('xmlsitemap_node_status_page', 1);
xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.5));
}
//function addNodes($count) {
......@@ -45,20 +45,6 @@ class XMLSitemapNodeTestHelper extends XMLSitemapTestHelper {
}
}
//class XMLSitemapNodeUnitTest extends DrupalWebTestCase {
// public static function getInfo() {
// return array(
// 'name' => 'XML Sitemap node unit tests',
// 'description' => 'Unit tests for the XML Sitemap node module.',
// 'group' => 'XML Sitemap',
// );
// }
//
// function setUp() {
// parent::setUp('xmlsitemap', 'xmlsitemap_node');
// }
//}
class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
public static function getInfo() {
return array(
......@@ -121,28 +107,33 @@ class XMLSitemapNodeFunctionalTest extends XMLSitemapNodeTestHelper {
$this->assertNodeSitemapLinkValues($node_old, array('status' => 1, 'priority' => 0.5));
$edit = array(
'xmlsitemap_node_status' => 0,
'xmlsitemap_node_priority' => '0.0',
'xmlsitemap[status]' => 0,
'xmlsitemap[priority]' => '0.0',
);
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertText(t('The content type Basic page has been updated.'));
$this->assertText('The content type Basic page has been updated.');
$node = $this->drupalCreateNode();
$this->assertNodeSitemapLinkValues($node, array('status' => 0, 'priority' => 0.0));
$this->assertNodeSitemapLinkValues($node_old, array('status' => 0, 'priority' => 0.0));
$edit = array(
'xmlsitemap_node_status' => 1,
'xmlsitemap_node_priority' => '0.5',
'type' => 'page2',
'xmlsitemap[status]' => 1,
'xmlsitemap[priority]' => '0.5',
);
$this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type'));
$this->assertText(t('The content type Basic page has been updated.'));
$this->assertText('Changed the content type of 2 posts from page to page2.');
$this->assertText('The content type Basic page has been updated.');
$this->assertNodeSitemapLinkValues($node, array('status' => 1, 'priority' => 0.5));
$this->assertNodeSitemapLinkValues($node_old, array('status' => 1, 'priority' => 0.5));
$this->assertNodeSitemapLinkValues($node, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertNodeSitemapLinkValues($node_old, array('subtype' => 'page2', 'status' => 1, 'priority' => 0.5));
$this->assertEqual(count(xmlsitemap_link_load_multiple(array('type' => 'node', 'subtype' => 'page'))), 0);