You are here

function xmlsitemap_engines_submit_sitemaps in XML sitemap 8

Same name and namespace in other branches
  1. 6.2 xmlsitemap_engines/xmlsitemap_engines.module \xmlsitemap_engines_submit_sitemaps()
  2. 7.2 xmlsitemap_engines/xmlsitemap_engines.module \xmlsitemap_engines_submit_sitemaps()
  3. 2.x xmlsitemap_engines/xmlsitemap_engines.module \xmlsitemap_engines_submit_sitemaps()

Submit the sitemaps to a specific URL.

Parameters

string $url: The URL for sitemap submission.

array $sitemaps: An array of URLs of the sitemaps to submit.

2 calls to xmlsitemap_engines_submit_sitemaps()
XmlSitemapEnginesFunctionalTest::testSubmitSitemaps in xmlsitemap_engines/tests/src/Functional/XmlSitemapEnginesFunctionalTest.php
Create sitemaps and send them to search engines.
xmlsitemap_engines_submit_engines in xmlsitemap_engines/xmlsitemap_engines.module
Submit the sitemaps to all the specified search engines.

File

xmlsitemap_engines/xmlsitemap_engines.module, line 131
Main file for the XML sitemap engines.

Code

function xmlsitemap_engines_submit_sitemaps($url, array $sitemaps) {
  foreach ($sitemaps as $sitemap) {
    $sitemap_path = UrlHelper::isExternal($sitemap->uri['path']) ? $sitemap->uri['path'] : 'base:/' . $sitemap->uri['path'];
    $sitemap_url = Url::fromUri($sitemap_path, $sitemap->uri['options'])
      ->toString();
    $submit_url = xmlsitemap_engines_prepare_url($url, $sitemap_url);
    try {
      $request = \Drupal::httpClient()
        ->get($submit_url);
      \Drupal::logger('xmlsitemap')
        ->notice('Submitted the sitemap to %url and received response @code.', [
        '%url' => $submit_url,
        '@code' => $request
          ->getStatusCode(),
      ]);
    } catch (RequestException $ex) {
      \Drupal::logger('xmlsitemap')
        ->alert('Submitted the sitemap to %url and received response @code.', [
        '%url' => $submit_url,
        '@code' => '404',
      ]);
    }
  }
}