PHP code example of in-square / pimcore-sitemap-bundle

1. Go to this page and download the library: Download in-square/pimcore-sitemap-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

in-square / pimcore-sitemap-bundle example snippets


return [
    InSquare\PimcoreSitemapBundle\InSquarePimcoreSitemapBundle::class => ['all' => true],
];



declare(strict_types=1);

namespace App\Sitemap;

use InSquare\PimcoreSitemapBundle\Generator\ObjectGeneratorInterface;
use InSquare\PimcoreSitemapBundle\Generator\SitemapItemData;
use Pimcore\Model\DataObject\Post;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

final class PostGenerator implements ObjectGeneratorInterface
{
    public function getId(): string
    {
        return 'post';
    }

    public function getObjectClass(): string
    {
        return Post::class;
    }

    public function buildItem(object $object, int $siteId, string $locale): ?SitemapItemData
    {
        if (!$object instanceof Post) {
            return null;
        }

        if (!$object->isPublished()) {
            return null;
        }

        $linkGenerator = $object->getClass()?->getLinkGenerator();
        if ($linkGenerator === null) {
            return null;
        }

        $url = $linkGenerator->generate($object, [
            'locale' => $locale,
            'siteId' => $siteId,
            'referenceType' => UrlGeneratorInterface::ABSOLUTE_URL,
        ]);

        $lastmod = (new \DateTimeImmutable())->setTimestamp($object->getModificationDate());

        return new SitemapItemData(
            $object->getId(),
            $object::class,
            $url,
            $lastmod
        );
    }
}