Commit c3fe4c26 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #2387341 by Dave Reid: Allow for additional context to be passed through...

Issue #2387341 by Dave Reid: Allow for additional context to be passed through xmlsitemap_link_save()
parent 7c15c7dc
......@@ -60,10 +60,12 @@ function hook_xmlsitemap_link_info() {
/**
* Alter the data of a sitemap link before the link is saved.
*
* @param $link
* @param array $link
* An array with the data of the sitemap link.
* @param array $context
* An optional context array containing data related to the link.
*/
function hook_xmlsitemap_link_alter(&$link) {
function hook_xmlsitemap_link_alter(array &$link, array $context) {
if ($link['type'] == 'mymodule') {
$link['priority'] += 0.5;
}
......@@ -75,10 +77,12 @@ function hook_xmlsitemap_link_alter(&$link) {
* @param $link
* Associative array defining an XML sitemap link as passed into
* xmlsitemap_link_save().
* @param array $context
* An optional context array containing data related to the link.
*
* @see hook_xmlsitemap_link_update()
*/
function hook_xmlsitemap_link_insert(array $link) {
function hook_xmlsitemap_link_insert(array $link, array $context) {
db_insert('mytable')
->fields(array(
'link_type' => $link['type'],
......@@ -94,10 +98,12 @@ function hook_xmlsitemap_link_insert(array $link) {
* @param $link
* Associative array defining an XML sitemap link as passed into
* xmlsitemap_link_save().
* @param array $context
* An optional context array containing data related to the link.
*
* @see hook_xmlsitemap_link_insert()
*/
function hook_xmlsitemap_link_update(array $link) {
function hook_xmlsitemap_link_update(array $link, array $context) {
db_update('mytable')
->fields(array(
'link_type' => $link['type'],
......
......@@ -560,10 +560,15 @@ function xmlsitemap_link_load_multiple(array $conditions = array()) {
/**
* Saves or updates a sitemap link.
*
* @param $link
* @param array $link
* An array with a sitemap link.
* @param array $context
* An optional context array containing data related to the link.
*
* @return array
* The saved sitemap link.
*/
function xmlsitemap_link_save(array $link) {
function xmlsitemap_link_save(array $link, array $context = array()) {
$link += array(
'access' => 1,
'status' => 1,
......@@ -577,7 +582,7 @@ function xmlsitemap_link_save(array $link) {
);
// Allow other modules to alter the link before saving.
drupal_alter('xmlsitemap_link', $link);
drupal_alter('xmlsitemap_link', $link, $context);
// Temporary validation checks.
// @todo Remove in final?
......@@ -599,11 +604,11 @@ function xmlsitemap_link_save(array $link) {
// Save the link and allow other modules to respond to the link being saved.
if ($existing) {
drupal_write_record('xmlsitemap', $link, array('type', 'id'));
module_invoke_all('xmlsitemap_link_update', $link);
module_invoke_all('xmlsitemap_link_update', $link, $context);
}
else {
drupal_write_record('xmlsitemap', $link);
module_invoke_all('xmlsitemap_link_insert', $link);
module_invoke_all('xmlsitemap_link_insert', $link, $context);
}
return $link;
......
......@@ -94,7 +94,7 @@ function xmlsitemap_menu_xmlsitemap_process_menu_links(array $mlids, array $xmls
$menu_item['xmlsitemap'] = $xmlsitemap;
}
$link = xmlsitemap_menu_create_link($menu_item);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $menu_item));
}
// Set the global user variable back to the original user.
......
......@@ -40,7 +40,7 @@ function xmlsitemap_node_xmlsitemap_process_node_links(array $nids) {
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
$link = xmlsitemap_node_create_link($node);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $node));
}
}
......@@ -56,7 +56,7 @@ function xmlsitemap_node_node_insert(stdClass $node) {
*/
function xmlsitemap_node_node_update(stdClass $node) {
$link = xmlsitemap_node_create_link($node);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $node));
}
/**
......
......@@ -50,7 +50,7 @@ function xmlsitemap_taxonomy_xmlsitemap_process_taxonomy_term_links(array $tids)
$terms = taxonomy_term_load_multiple($tids);
foreach ($terms as $term) {
$link = xmlsitemap_taxonomy_create_link($term);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $term));
}
}
......@@ -107,7 +107,7 @@ function xmlsitemap_taxonomy_vocabulary_update(stdClass $vocabulary) {
*/
function xmlsitemap_taxonomy_term_insert(stdClass $term) {
$link = xmlsitemap_taxonomy_create_link($term);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $term));
}
/**
......@@ -115,7 +115,7 @@ function xmlsitemap_taxonomy_term_insert(stdClass $term) {
*/
function xmlsitemap_taxonomy_term_update(stdClass $term) {
$link = xmlsitemap_taxonomy_create_link($term);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $term));
}
/**
......
......@@ -37,7 +37,7 @@ function xmlsitemap_user_xmlsitemap_process_user_links(array $uids) {
$accounts = user_load_multiple($uids);
foreach ($accounts as $account) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $account));
}
}
......@@ -51,7 +51,7 @@ function xmlsitemap_user_user_presave(&$edit, $account, $category) {
$link = $edit['xmlsitemap'] + $link;
unset($edit['xmlsitemap']);
}
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $account));
}
}
......@@ -60,7 +60,7 @@ function xmlsitemap_user_user_presave(&$edit, $account, $category) {
*/
function xmlsitemap_user_user_insert(&$edit, $account, $category) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $account));
}
/**
......@@ -68,7 +68,7 @@ function xmlsitemap_user_user_insert(&$edit, $account, $category) {
*/
function xmlsitemap_user_user_update(&$edit, $account, $category) {
$link = xmlsitemap_user_create_link($account);
xmlsitemap_link_save($link);
xmlsitemap_link_save($link, array($link['type'] => $account));
}
/**
......
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