Last active
July 1, 2020 10:46
-
-
Save hissy/b056ac83f179e22eb55d4225d216de9e to your computer and use it in GitHub Desktop.
[concrete5] Add express entry details into sitemap.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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/', 'view_express_entity', $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