You are here

function xmlsitemap_install in XML sitemap 8

Same name and namespace in other branches
  1. 5.2 xmlsitemap/xmlsitemap.install \xmlsitemap_install()
  2. 5 xmlsitemap.install \xmlsitemap_install()
  3. 6.2 xmlsitemap.install \xmlsitemap_install()
  4. 6 xmlsitemap.install \xmlsitemap_install()
  5. 7.2 xmlsitemap.install \xmlsitemap_install()
  6. 2.x xmlsitemap.install \xmlsitemap_install()

Implements hook_install().

1 call to xmlsitemap_install()
KernelTestBase::setUp in tests/src/Kernel/KernelTestBase.php

File

./xmlsitemap.install, line 299
Install, update and uninstall functions for the xmlsitemap module.

Code

function xmlsitemap_install() {

  // Set this module's weight to 1 so xmlsitemap_cron() runs after all other
  // xmlsitemap_x_cron() runs.
  module_set_weight('xmlsitemap', 1);

  // Insert the homepage link into the {xmlsitemap} table so we do not show an
  // empty sitemap after install.
  \Drupal::database()
    ->insert('xmlsitemap')
    ->fields([
    'type' => 'frontpage',
    'id' => 0,
    'loc' => '/',
    'priority' => \Drupal::config('xmlsitemap.settings')
      ->get('frontpage_priority'),
    'changefreq' => \Drupal::config('xmlsitemap.settings')
      ->get('frontpage_changefreq'),
    'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
  ])
    ->execute();
  $state_variables = xmlsitemap_state_variables();
  \Drupal::state()
    ->setMultiple($state_variables);
  $xmlsitemap_base_url = rtrim(Url::fromRoute('<front>', [], [
    'absolute' => TRUE,
  ])
    ->toString(), '/');
  \Drupal::state()
    ->set('xmlsitemap_base_url', $xmlsitemap_base_url);
  $context = xmlsitemap_get_current_context();
  $sitemap = \Drupal::entityTypeManager()
    ->getStorage('xmlsitemap')
    ->create([
    'id' => xmlsitemap_sitemap_get_context_hash($context),
  ]);
  $sitemap->context = xmlsitemap_get_current_context();
  $sitemap = $sitemap
    ->setLabel(\Drupal::state()
    ->get('xmlsitemap_base_url'));
  $sitemap
    ->save();
  xmlsitemap_check_directory();
  \Drupal::state()
    ->set('xmlsitemap_regenerate_needed', TRUE);
}