Skip to content

Instantly share code, notes, and snippets.

@hissy
Created July 1, 2020 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/f064e6321c3c8f8acdb045b6acee3897 to your computer and use it in GitHub Desktop.
Save hissy/f064e6321c3c8f8acdb045b6acee3897 to your computer and use it in GitHub Desktop.
[concrete5] Add express entry details into sitemap.xml
<?php
/* @var Concrete\Core\Application\Application $app */
/* @var Concrete\Core\Console\Application $console only set in CLI environment */
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $director */
$director = $app->make(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class);
$director->addListener('on_sitemap_xml_ready', static function ($event) use ($app) {
/** @var \Concrete\Core\Page\Sitemap\Event\XmlReadyEvent $event */
$xml = $event->getDocument();
$entity = Express::getObjectByHandle('test');
if (is_object($entity)) {
$resolver = $app->make(\Concrete\Core\Url\Resolver\Manager\ResolverManagerInterface::class);
$list = new \Concrete\Core\Express\EntryList($entity);
$entries = $list->getResults();
/** @var \Concrete\Core\Entity\Express\Entry $entry */
foreach ($entries as $entry) {
$id = $entry->getID();
$lastMod = $entry->getDateModified()->format(DateTime::ATOM);
$url = $xml->addChild('url');
$url->addChild('loc', $resolver->resolve(['/express/detail/', $id]));
$url->addChild('lastmod', $lastMod);
$url->addChild('priority', 0.5);
$url->addChild('changefreq', 'weekly');
}
}
$event->setDocument($xml);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment