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

test: for reference site #148

Open
wants to merge 1 commit into
base: reference
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading