0

I installed SeoBundle and configured the bundle to build a sitemap (docs).

AppKernel.php:

new Sonata\SeoBundle\SonataSeoBundle(),
new Symfony\Cmf\Bundle\CoreBundle\CmfCoreBundle(),
new Symfony\Cmf\Bundle\SeoBundle\CmfSeoBundle(),

Full bundle configurations (config.yml):

sonata_seo:
    page:
        title: Erasmus internship – Training Experience
        metas:
            name:
                keywords: Erasmus Internships, Internship in Europe, International Internships, Erasmus+, Erasmus Entrepreneur, Student Internships, Internships Abroad, Student Placements
                description: Find Internships with Training Experience: Students can find internships & employment opportunities in Europe’s platform for internships. Search paid internships and placements abroad.
                viewport: width=device-width, initial-scale=1
                format-detection: telephone=no
                robots: index, follow
            property:
                'og:site_name': Training Experience
                'og:title': Erasmus internship – Training Experience
                'og:description': Find Internships with Training Experience: Students can find internships & employment opportunities in Europe’s platform for internships. Search paid internships and placements abroad."
                'og:url': https://www.trainingexperience.org
                'og:image': https://www.trainingexperience.org/bundles/index/images/tx-orange.png
            http-equiv:
                'Content-Type':         text/html; charset=utf-8
        head:
            'xmlns':              http://www.w3.org/1999/xhtml
            'xmlns:og':           http://opengraphprotocol.org/schema/

cmf_seo:
    title: seo.title
    description: seo.description
    sitemap:
        enabled: true
    content_listener:
        enabled: false

Added routes to routing.yml:

sitemaps:
    prefix: /sitemaps
    resource: "@CmfSeoBundle/Resources/config/routing/sitemap.xml"

Now when I access /sitemaps/sitemap.xml it is opened, but no urls are listed:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"></urlset>

What could I be missing?

1 Answers1

0

Important for the items on sitemat is, that they got a matching (allowed, and sitemap name) as a content. Mostly the content isn't loaded. To do so your Content have to implement \Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface, which forces you to implement and fill a flag. You can find an example in the tests: SitemapAwareContent:

<?php

/*
 * This file is part of the Symfony CMF package.
 *
 * (c) 2011-2017 Symfony CMF
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Cmf\Bundle\SeoBundle\Tests\Resources\Document;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface;
use Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface;
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;
use Symfony\Component\Routing\Route;

/**
 * @PHPCRODM\Document(referenceable=true, translator="attribute")
 *
 * @author Maximilian Berghoff <Maximilian.Berghoff@gmx.de>
 */
class SitemapAwareContent extends ContentBase implements RouteReferrersReadInterface, TranslatableInterface, SitemapAwareInterface
{
    /**
     * @var string
     *
     * @PHPCRODM\Locale
     */
    protected $locale;

    /**
     * @var ArrayCollection|Route[]
     *
     * @PHPCRODM\Referrers(
     *  referringDocument="Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route",
     *  referencedBy="content"
     * )
     */
    protected $routes;

    /**
     * @var bool
     *
     * @PHPCRODM\Field(type="boolean",property="visible_for_sitemap")
     */
    private $isVisibleForSitemap;

    /**
     * @var string
     *
     * @PHPCRODM\Field(type="string",translated=true)
     */
    protected $title;

    public function __construct()
    {
        $this->routes = new ArrayCollection();
    }

    /**
     * @param string $sitemap
     *
     * @return bool
     */
    public function isVisibleInSitemap($sitemap)
    {
        return $this->isVisibleForSitemap;
    }

    /**
     * @param bool $isVisibleForSitemap
     *
     * @return SitemapAwareContent
     */
    public function setIsVisibleForSitemap($isVisibleForSitemap)
    {
        $this->isVisibleForSitemap = $isVisibleForSitemap;

        return $this;
    }

    /**
     * Add a route to the collection.
     *
     * @param Route $route
     */
    public function addRoute($route)
    {
        $this->routes->add($route);
    }

    /**
     * Remove a route from the collection.
     *
     * @param Route $route
     */
    public function removeRoute($route)
    {
        $this->routes->removeElement($route);
    }

    /**
     * Get the routes that point to this content.
     *
     * @return Route[] Route instances that point to this content
     */
    public function getRoutes()
    {
        return $this->routes;
    }

    /**
     * @return string|bool the locale of this model or false if
     *                     translations are disabled in this project
     */
    public function getLocale()
    {
        return $this->locale;
    }

    /**
     * @param string|bool $locale the local for this model, or false if
     *                            translations are disabled in this project
     */
    public function setLocale($locale)
    {
        $this->locale = $locale;
    }
}

you will also see that implementing the interface isn't the only task, you have to set the doctrine mapping also. Doing so, the default loader will fetch you documents and see them (they are visible now). But you can implement your own loader, voter (another decission item to select) and guesser (to fill in extra data) on your own. So you can decide which content is visible on which (you can have several) sitemap.

The documentation currently shows the process for the loaders, voter and guessers only, so we should insert some hints for the default visibility flag and the default usage at all. So i created an issue. It would be nice to get some feedback there, too.