Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
fix: [SDPAP-8510] custom url issue (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-gao authored Mar 27, 2024
1 parent 5a1f99c commit 39798d1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions modules/tide_site_simple_sitemap/tide_site_simple_sitemap.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\simple_sitemap\Entity\SimpleSitemap;
use Drupal\simple_sitemap\Entity\SimpleSitemapInterface;
use Drupal\taxonomy\Entity\Term;

/**
* Implements hook_ENTITY_TYPE_delete().
Expand All @@ -29,3 +30,34 @@ function tide_site_simple_sitemap_taxonomy_term_delete($term) {
watchdog_exception('tide_site_simple_sitemap', $exception);
}
}

/**
* Implements hook_ENTITY_TYPE_insert().
*/
function tide_site_simple_sitemap_simple_sitemap_insert(SimpleSitemap $entity) {
$sitemap_id =$entity->id();
if ($term_id = _tide_site_simple_sitemap_extract_site_number($sitemap_id)){
if(Term::load($term_id) && $entity->getType()->getOriginalId() === 'tide_default_sitemap_type'){
/** @var Drupal\simple_sitemap\Manager\Generator $custom_generator */
$custom_generator = \Drupal::service('simple_sitemap.generator');
$custom_generator->setSitemaps($entity->id());
$site_based_custom_link = $custom_generator->customLinkManager()->get('/');
if (isset($site_based_custom_link[$sitemap_id]) && empty($site_based_custom_link[$sitemap_id])){
$custom_generator->customLinkManager()->add(
'/',
["path" => "/", "priority" => "1.0", "changefreq" => "daily"]
);
}
}
}
}

/**
* Extract site number from the sitemap id.
*/
function _tide_site_simple_sitemap_extract_site_number($string) {
if (preg_match('/^site-(\d+)$/', $string, $matches)) {
return $matches[1];
}
return null;
}

0 comments on commit 39798d1

Please sign in to comment.