You are here

function xmlsitemap_link_save in XML sitemap 7.2

Same name and namespace in other branches
  1. 6.2 xmlsitemap.module \xmlsitemap_link_save()

Saves or updates a sitemap link.

Parameters

array $link: An array with a sitemap link.

array $context: An optional context array containing data related to the link.

Return value

array The saved sitemap link.

Related topics

16 calls to xmlsitemap_link_save()
XMLSitemapTestHelper::addSitemapLink in ./xmlsitemap.test
Add Sitemap Link.
XMLSitemapUnitTest::testSaveLink in ./xmlsitemap.test
Tests for xmlsitemap_link_save().
xmlsitemap_custom_edit_link_form_submit in xmlsitemap_custom/xmlsitemap_custom.admin.inc
Edit Link Form Submit.
xmlsitemap_custom_scan_directories in xmlsitemap_custom/xmlsitemap_custom.scan.inc
Scan directories and keep matching subtrees of the custom XML sitemap.
xmlsitemap_link_presave in ./xmlsitemap.module
Presave a sitemap link.

... See full list

File

./xmlsitemap.module, line 643
xmlsitemap XML sitemap

Code

function xmlsitemap_link_save(array $link, array $context = array()) {
  $link += array(
    'access' => 1,
    'status' => 1,
    'status_override' => 0,
    'lastmod' => 0,
    'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
    'priority_override' => 0,
    'changefreq' => 0,
    'changecount' => 0,
    'language' => LANGUAGE_NONE,
  );

  // Allow other modules to alter the link before saving.
  drupal_alter('xmlsitemap_link', $link, $context);

  // Temporary validation checks.
  // @todo Remove in final?
  if ($link['priority'] < 0 || $link['priority'] > 1) {
    trigger_error(t('Invalid sitemap link priority %priority.<br />@link', array(
      '%priority' => $link['priority'],
      '@link' => var_export($link, TRUE),
    )), E_USER_ERROR);
  }
  if ($link['changecount'] < 0) {
    trigger_error(t('Negative changecount value. Please report this to <a href="@516928">@516928</a>.<br />@link', array(
      '@516928' => 'https://www.drupal.org/node/516928',
      '@link' => var_export($link, TRUE),
    )), E_USER_ERROR);
    $link['changecount'] = 0;
  }
  $existing = db_query_range("SELECT loc, access, status, lastmod, priority, changefreq, changecount, language FROM {xmlsitemap} WHERE type = :type AND id = :id", 0, 1, array(
    ':type' => $link['type'],
    ':id' => $link['id'],
  ))
    ->fetchAssoc();

  // Check if this is a changed link and set the regenerate flag if necessary.
  if (!variable_get('xmlsitemap_regenerate_needed', FALSE)) {
    _xmlsitemap_check_changed_link($link, $existing, TRUE);
  }

  // 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, $context);
  }
  else {
    drupal_write_record('xmlsitemap', $link);
    module_invoke_all('xmlsitemap_link_insert', $link, $context);
  }
  return $link;
}