Commit a6553960 authored by Dave Reid's avatar Dave Reid
Browse files

by Dave Reid: Changed xmlsitemap_add_form_link_options() to use entity,...

by Dave Reid: Changed xmlsitemap_add_form_link_options() to use entity, bundle, and ID parameters instead of a link array.
parent 0cfa2088
......@@ -469,8 +469,27 @@ function xmlsitemap_bundle_settings_dialog($entity, $bundle, $ajax = FALSE) {
*
* @todo Add changefreq overridability.
*/
function xmlsitemap_add_form_link_options(&$form, $link) {
$info = xmlsitemap_get_link_info($link['type']);
function xmlsitemap_add_form_link_options(&$form, $entity, $bundle, $id) {
$info = xmlsitemap_get_link_info($entity);
if (!$info || empty($info['bundles'][$bundle])) {
return;
}
if (!$link = xmlsitemap_link_load($entity, $id)) {
$link = array();
}
$settings = xmlsitemap_link_bundle_load($entity, $bundle);
$link += array(
'access' => 1,
'status' => $settings['status'],
'status_default' => $settings['status'],
'status_override' => 0,
'priority' => $settings['priority'],
'priority_default' => $settings['priority'],
'priority_override' => 0,
);
$form['xmlsitemap'] = array(
'#type' => 'fieldset',
......@@ -478,7 +497,7 @@ function xmlsitemap_add_form_link_options(&$form, $link) {
'#title' => t('XML sitemap'),
'#collapsible' => TRUE,
'#collapsed' => !$link['status_override'] && !$link['priority_override'],
'#access' => user_access('administer xmlsitemap'),
'#access' => user_access('administer xmlsitemap') || xmlsitemap_can_admin_bundle($entity, $bundle),
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
......@@ -492,8 +511,8 @@ function xmlsitemap_add_form_link_options(&$form, $link) {
unset($form['xmlsitemap']['#attached']['js']['vertical-tabs']);
}
$bundle_info = $info['bundles'][$link['subtype']];
if (xmlsitemap_can_admin_bundle($link['type'], $link['subtype']) && $path = xmlsitemap_get_bundle_path($link['type'], $link['subtype'])) {
$bundle_info = $info['bundles'][$bundle];
if (xmlsitemap_can_admin_bundle($entity, $bundle) && $path = xmlsitemap_get_bundle_path($entity, $bundle)) {
$form['xmlsitemap']['description'] = array(
'#prefix' => '<div class="description">',
'#suffix' => '</div>',
......@@ -503,7 +522,7 @@ function xmlsitemap_add_form_link_options(&$form, $link) {
// Show a warning if the link is not accessible and will not be included in
// the sitemap.
if (!$link['access']) {
if ($id && !$link['access']) {
$form['xmlsitemap']['warning'] = array(
'#type' => 'markup',
'#prefix' => '<p><strong>',
......
......@@ -102,6 +102,16 @@ function xmlsitemap_menu_form_menu_edit_menu_alter(&$form, $form_state) {
// xmlsitemap_menu_xmlsitemap_process_menu_links($mlids);
//}
function xmlsitemap_menu_form_menu_edit_item_alter(&$form, $form_state) {
$menu_name = $form['parent']['#default_value'];
$menu_name = substr($menu_name, 0, strpos($menu_name, ':'));
// Add the link options.
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, 'menu', $menu_name, $form['mlid']['#value']);
$form['xmlsitemap']['#weight'] = 30;
}
/**
* Implements hook_menu_insert().
*/
......@@ -176,6 +186,12 @@ function xmlsitemap_menu_create_link(array $menu_item) {
'priority_override' => 0,
);
//if (!isset($menu_item['access'])) {
// xmlsitemap_switch_user(0);
// $menu_item = menu_link_load($menu_item['mlid']);
// xmlsitemap_restore_user();
//}
// The following values must always be checked because they are volatile.
$menu_item['xmlsitemap']['subtype'] = $menu_item['menu_name'];
$menu_item['xmlsitemap']['access'] = $menu_item['access'] && !$menu_item['external'] && !$menu_item['hidden'];
......
......@@ -168,17 +168,9 @@ function xmlsitemap_node_type_form_submit($form, &$form_state) {
*/
function xmlsitemap_node_form_alter(&$form, $form_state, $form_id) {
if (!empty($form['#node_edit_form'])) {
$node = clone $form['#node'];
if (!isset($node->nid)) {
// Handle new nodes that do not have a value for nid yet.
$node->nid = NULL;
}
$link = xmlsitemap_node_create_link($node);
// Add the link options.
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, $link);
xmlsitemap_add_form_link_options($form, 'node', $form['type']['#value'], $form['nid']['#value']);
$form['xmlsitemap']['#access'] |= user_access('administer nodes');
$form['xmlsitemap']['#weight'] = 30;
}
......
......@@ -77,19 +77,9 @@ function xmlsitemap_taxonomy_form_taxonomy_form_vocabulary_alter(&$form, $form_s
* Implements hook_form_FORM_ID_alter().
*/
function xmlsitemap_taxonomy_form_taxonomy_form_term_alter(&$form, $form_state) {
if ($form['#term']['tid']) {
$term = taxonomy_term_load($form['#term']['tid']);
}
else {
$term = (object) $form['#term'];
}
$term->vid = $form['vid']['#value'];
$link = xmlsitemap_taxonomy_create_link($term);
// Add the link options.
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, $link);
$form['xmlsitemap']['#access'] |= user_access('administer taxonomy');
xmlsitemap_add_form_link_options($form, 'taxonomy_term', $form['vid']['#value'], $form['#term']['tid']);
}
/**
......
......@@ -5,7 +5,7 @@
* Implements hook_entity_info_alter().
*/
function xmlsitemap_user_entity_info_alter(&$entity_info) {
$entity_info['user']['bundle label'] = t('Users');
$entity_info['user']['bundle label'] = t('User');
$entity_info['user']['xmlsitemap'] = array(
'process callback' => 'xmlsitemap_user_xmlsitemap_process_user_links',
);
......@@ -43,25 +43,35 @@ function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) {
}
/**
* Implements hook_user_insert().
* Implements hook_user_presave().
*/
function xmlsitemap_user_user_insert(&$edit, $account, $category) {
function xmlsitemap_user_user_presave(&$edit, $account, $category) {
$link = xmlsitemap_user_create_link($account);
if (isset($edit['xmlsitemap'])) {
$link = $edit['xmlsitemap'] + $link;
unset($edit['xmlsitemap']);
}
xmlsitemap_save_link($link);
}
/**
* Implements hook_user_insert().
* Implements hook_user_cancel().
*/
function xmlsitemap_user_user_update(&$edit, $account, $category) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_save_link($link);
}
function xmlsitemap_user_user_cancel($edit, $account, $method) {
xmlsitemap_link_delete('user', $account->uid);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* @see user_admin_settings()
* @see xmlsitemap_add_link_bundle_settings()
*/
function xmlsitemap_user_form_user_profile_form_alter(&$form, $form_state) {
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, 'user', 'user', $form['#user']->uid);
}
/**
* Implements hook_form_FORM_ID_alter().
*
......@@ -79,7 +89,7 @@ function xmlsitemap_user_form_user_admin_settings_alter(&$form, $form_state) {
function xmlsitemap_user_user_admin_settings_submit($form, &$form_state) {
xmlsitemap_link_bundle_settings_save('user', 'user', $form_state['values']['xmlsitemap']);
// Do not allow node_type_form_submit() to run variable_set() on this.
// Do not allow system_settings_form_submit() to run variable_set() on this.
unset($form_state['values']['xmlsitemap']);
}
......@@ -106,7 +116,7 @@ function xmlsitemap_user_create_link(stdClass &$account) {
'subtype' => 'user',
'id' => $account->uid,
'loc' => 'user/' . $account->uid,
'status' => 1, // @todo $settings['status'] defaults to 0 so fix this
'status' => $settings['status'],
'status_default' => $settings['status'],
'status_override' => 0,
'priority' => $settings['priority'],
......@@ -115,7 +125,7 @@ function xmlsitemap_user_create_link(stdClass &$account) {
);
// The following values must always be checked because they are volatile.
$account->xmlsitemap['access'] = $account->uid && $account->status && $account->access;
$account->xmlsitemap['access'] = $account->uid && $account->status && $account->login && $account->access;
$account->xmlsitemap['language'] = !empty($account->language) ? $account->language : LANGUAGE_NONE;
return $account->xmlsitemap;
......
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