Commit 8602ad89 authored by Dave Reid's avatar Dave Reid

#661780 by Dave Reid: Added Dialog API integration for easy editing of bundle settings.

parent 43418728
......@@ -271,6 +271,7 @@ function xmlsitemap_rebuild_form_submit($form, &$form_state) {
function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info) {
$priorities = xmlsitemap_get_priority_options(NULL, FALSE);
$statuses = xmlsitemap_get_status_options(NULL);
$destination = drupal_get_destination();
$rows = array();
$totals = array('total' => 0, 'indexed' => 0, 'visible' => 0);
......@@ -282,8 +283,15 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
$totals['visible'] += $status['visible'];
$row = array();
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()));
if (xmlsitemap_can_admin_bundle($entity, $bundle) && !empty($bundle_info['admin']['real path'])) {
$path = $bundle_info['admin']['real path'];
$options = array('query' => $destination);
if (module_exists('dialog')) {
$form['#attached']['library']['dialog'] = array('dialog', 'dialog');
$path = "admin/config/search/xmlsitemap/settings/$entity/$bundle/nojs";
$options['attributes']['class'] = array('use-dialog', 'use-ajax');
}
$row[] = l($bundle_info['label'], $path, $options);
}
else {
$row[] = $bundle_info['label'];
......@@ -341,6 +349,12 @@ function xmlsitemap_add_form_entity_summary(&$form, $entity, array $entity_info)
function xmlsitemap_add_link_bundle_settings(array &$form, array $form_state, $entity, $bundle) {
xmlsitemap_link_bundle_settings_form($form, $form_state, $entity, $bundle, FALSE);
// Manually call drupal_alter() on the $options form since it was not called
// using drupal_get_form().
$form_id = 'xmlsitemap_link_bundle_settings_form';
drupal_alter('form_' . $form_id, $form, $form_state);
drupal_alter('form', $form, $form_state, $form_id);
// Make the base element a fieldset.
$form['xmlsitemap'] += array(
'#type' => 'fieldset',
......@@ -363,7 +377,7 @@ function xmlsitemap_add_link_bundle_settings(array &$form, array $form_state, $e
}
function xmlsitemap_link_bundle_settings_form(array &$form, array $form_state, $entity, $bundle, $buttons = TRUE) {
$settings = xmlsitemap_link_bundle_settings_load($entity, $bundle);
$settings = xmlsitemap_link_bundle_load($entity, $bundle);
$form['xmlsitemap'] = array(
'#tree' => TRUE,
......@@ -414,6 +428,32 @@ function xmlsitemap_link_bundle_settings_form_submit($form, $form_state) {
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'])));
}
function xmlsitemap_bundle_settings_dialog($entity, $bundle, $ajax = FALSE) {
$info = xmlsitemap_get_link_info($entity);
if (!$ajax) {
if (!empty($info['bundles'][$bundle]['admin']['real path'])) {
$destination = drupal_get_destination();
unset($_GET['destination']);
drupal_goto($info['bundles'][$bundle]['admin']['real path'], array('query' => $destination));
}
return MENU_NOT_FOUND;
}
if (!isset($info['bundles'][$bundle]) || !xmlsitemap_can_admin_bundle($entity, $bundle)) {
$output = array();
$output[] = dialog_command_display(t('You are not authorized to access this page.'), array('title' => t('Access denied')));
ajax_render($output);
}
$content = drupal_get_form('xmlsitemap_link_bundle_settings_form', $entity, $bundle);
$options = array(
'title' => t('@bundle XML sitemap settings', array('@bundle' => $info['bundles'][$bundle]['label'])),
);
$output[] = dialog_command_display($content, $options);
ajax_render($output);
}
/**
* Add a link's XML sitemap options to the link's form.
*
......@@ -443,7 +483,7 @@ function xmlsitemap_add_form_link_options(&$form, $link) {
}
$bundle_info = $info['bundles'][$link['subtype']];
if (xmlsitemap_can_admin_bundle($bundle_info) && !empty($bundle_info['admin']['real path'])) {
if (xmlsitemap_can_admin_bundle($link['type'], $link['subtype']) && !empty($bundle_info['admin']['real path'])) {
$form['xmlsitemap']['description'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
......
......@@ -10,6 +10,7 @@ files[] = xmlsitemap.drush.inc
files[] = xmlsitemap.pages.inc
files[] = xmlsitemap.install
files[] = xmlsitemap.test
recommends[] = dialog
recommends[] = robotstxt
recommends[] = vertical_tabs
configure = admin/config/search/xmlsitemap
......@@ -40,6 +40,7 @@ function xmlsitemap_help($path, $arg) {
switch ($path) {
case 'admin/help/xmlsitemap':
case 'admin/config/search/xmlsitemap/settings/%/%/%':
return;
case 'admin/help#xmlsitemap':
$sitemaps = xmlsitemap_get_sitemaps(TRUE);
......@@ -131,6 +132,17 @@ function xmlsitemap_menu() {
'file' => 'xmlsitemap.pages.inc',
);
// CTools/Dialog API callback for editing bundle settings.
if (module_exists('dialog')) {
$items['admin/config/search/xmlsitemap/settings/%/%/%dialog_js'] = array(
'page callback' => 'xmlsitemap_bundle_settings_dialog',
'page arguments' => array(5, 6, 7),
'access arguments' => array('administer xmlsitemap'),
'type' => MENU_CALLBACK,
'file' => 'xmlsitemap.admin.inc',
);
}
return $items;
}
......@@ -812,7 +824,7 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
$bundle_info += array(
'xmlsitemap' => array(),
);
$bundle_info['xmlsitemap'] += xmlsitemap_link_bundle_settings_load($key, $bundle);
$bundle_info['xmlsitemap'] += xmlsitemap_link_bundle_load($key, $bundle);
}
}
drupal_alter('xmlsitemap_link_info', $link_info);
......@@ -947,7 +959,7 @@ 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) {
$settings = xmlsitemap_link_bundle_settings_load($entity_type, $bundle);
$settings = xmlsitemap_link_bundle_load($entity_type, $bundle);
if (!empty($settings['status'])) {
//if (!empty($bundle_info['xmlsitemap']['status'])) {
$bundles[] = $bundle;
......@@ -982,7 +994,7 @@ function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
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);
$old_settings = xmlsitemap_link_bundle_load($entity, $bundle);
if ($settings['status'] != $old_settings['status']) {
xmlsitemap_update_links(array('status' => $settings['status']), array('type' => $entity, 'subtype' => $bundle, 'status_override' => 0));
}
......@@ -998,14 +1010,14 @@ function xmlsitemap_link_bundle_settings_save($entity, $bundle, array $settings,
function xmlsitemap_link_bundle_rename($entity, $bundle_old, $bundle_new) {
if ($bundle_old != $bundle_new) {
$settings = xmlsitemap_link_bundle_settings_load($entity, $bundle_old);
$settings = xmlsitemap_link_bundle_load($entity, $bundle_old);
variable_del("xmlsitemap_settings_{$entity}_{$bundle_old}");
xmlsitemap_link_bundle_settings_save($entity, $bundle_new, $settings, FALSE);
xmlsitemap_update_links(array('subtype' => $bundle_new), array('type' => $entity, 'subtype' => $bundle_old));
}
}
function xmlsitemap_link_bundle_settings_load($entity, $bundle) {
function xmlsitemap_link_bundle_load($entity, $bundle) {
$settings = variable_get("xmlsitemap_settings_{$entity}_{$bundle}", array());
$settings += array('status' => 0, 'priority' => 0.5);
return $settings;
......@@ -1020,14 +1032,19 @@ function xmlsitemap_link_bundle_delete($entity, $bundle, $delete_links = 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']);
function xmlsitemap_can_admin_bundle($entity, $bundle) {
$info = xmlsitemap_get_link_info($entity);
if (isset($info['bundles'][$bundle]['admin'])) {
$admin = $info['bundles'][$bundle]['admin'];
$admin += array('access arguments' => array());
if (!isset($admin['access callback']) && count($admin['access arguments']) == 1) {
$admin['access callback'] = 'user_access';
}
if (!empty($admin['access callback'])) {
return call_user_func_array($admin['access callback'], $admin['access arguments']);
}
}
......
......@@ -162,7 +162,7 @@ function xmlsitemap_menu_create_link(array $menu_item) {
}
}
$settings = xmlsitemap_link_bundle_settings_load('menu', $menu_item['menu_name']);
$settings = xmlsitemap_link_bundle_load('menu', $menu_item['menu_name']);
$menu_item['xmlsitemap'] += array(
'type' => 'menu',
......
......@@ -218,7 +218,7 @@ function xmlsitemap_node_create_link(&$node) {
}
}
$settings = xmlsitemap_link_bundle_settings_load('node', $node->type);
$settings = xmlsitemap_link_bundle_load('node', $node->type);
$node->xmlsitemap += array(
'type' => 'node',
......
......@@ -21,7 +21,7 @@ function xmlsitemap_taxonomy_xmlsitemap_link_info_alter(&$link_info) {
// Adjust the edit path to the *real* edit path.
$link_info['taxonomy_term']['bundles'][$machine_name]['admin']['path'] .= '/edit';
$link_info['taxonomy_term']['bundles'][$machine_name]['admin']['real path'] .= '/edit';
$link_info['taxonomy_term']['bundles'][$machine_name]['xmlsitemap'] = xmlsitemap_link_bundle_settings_load('taxonomy_term', $vocabulary->vid);
$link_info['taxonomy_term']['bundles'][$machine_name]['xmlsitemap'] = xmlsitemap_link_bundle_load('taxonomy_term', $vocabulary->vid);
$link_info['taxonomy_term']['bundles'][$vocabulary->vid] = $link_info['taxonomy_term']['bundles'][$machine_name];
unset($link_info['taxonomy_term']['bundles'][$machine_name]);
}
......@@ -175,7 +175,7 @@ function xmlsitemap_taxonomy_create_link(stdClass $term) {
}
}
$settings = xmlsitemap_link_bundle_settings_load('taxonomy_term', $term->vid);
$settings = xmlsitemap_link_bundle_load('taxonomy_term', $term->vid);
$term->xmlsitemap += array(
'id' => $term->tid,
......@@ -240,18 +240,3 @@ function xmlsitemap_taxonomy_get_node_count(stdClass $term) {
// @todo Use db_rewrite_sql() w/ switch user.
return db_query_range("SELECT COUNT(ti.nid) FROM {taxonomy_index} ti LEFT JOIN {node n} USING (nid) WHERE ti.tid = :tid AND n.status = 1", 0, 1, array(':tid' => $term->tid))->fetchField();
}
/**
* Internal default variables for template_var().
*/
function xmlsitemap_taxonomy_variables() {
$defaults = array();
$vids = array_keys(taxonomy_get_vocabularies());
foreach ($vids as $vid) {
$defaults['xmlsitemap_settings_taxonomy_term_' . $vid] = array(
'status' => 0,
'priority' => 0.5,
);
}
return $defaults;
}
Markdown is supported
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