Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Mynamespace;
  4.  
  5. use SilverStripe\ORM\ArrayList;
  6. use SilverStripe\CMS\Model\SiteTree;
  7. use TractorCow\Fluent\Model\Locale;
  8. use Wilr\GoogleSitemaps\GoogleSitemap;
  9.  
  10. /**
  11.  * Alters the output of the Google Sitemaps module to account for
  12.  * one SiteTree sitemap per configured Locale.
  13.  *
  14.  * Add to YAML config:
  15.  * SilverStripe\Core\Injector\Injector:
  16.  *   Wilr\GoogleSitemaps\GoogleSitemap:
  17.  *     class: Mynamespace\FluentGoogleSitemap
  18.  */
  19.  
  20. class FluentGoogleSitemap extends GoogleSitemap
  21. {
  22.     /**
  23.      * The google site map is broken down into multiple smaller files to
  24.      * prevent overbearing a server. By default separate {@link DataObject}
  25.      * records are keep in separate files and broken down into chunks.
  26.      *
  27.      * For SiteTree objects, one
  28.      *
  29.      * @return ArrayList
  30.      */
  31.     public function getSitemaps()
  32.     {
  33.         // Get the list of sitemaps
  34.         $sitemaps = parent::getSitemaps();
  35.         // Repeat the SiteTree once for each Locale
  36.         $out = ArrayList::create();
  37.         foreach ($sitemaps as $sitemap) {
  38.             if ($sitemap->ClassName === $this->sanitiseClassName(SiteTree::class)) {
  39.                 foreach (Locale::getLocales() as $locale) {
  40.                     $newSitemap = clone $sitemap;
  41.                     $newSitemap->Page = $newSitemap->Page.'?l='.$locale->Locale;
  42.                     $out->push($newSitemap);
  43.                 }
  44.             } else {
  45.                 $out->push($sitemap);
  46.             }
  47.         }
  48.         return $out;
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement