Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

SitemapBundle/Controller/SitemapController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\SitemapBundle\Controller;
4
5
use Kunstmaan\SitemapBundle\Event\PreSitemapRenderEvent;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\Routing\Annotation\Route;
10
11
class SitemapController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
12
{
13
    /**
14
     * This will generate a sitemap for the specified locale.
15
     * Use the mode parameter to select in which mode the sitemap should be
16
     * generated. At this moment only XML is supported
17
     *
18
     * @Route("/sitemap-{locale}.{_format}", name="KunstmaanSitemapBundle_sitemap",
19
     *                                       requirements={"_format" = "xml"})
20
     * @Template("@KunstmaanSitemap/Sitemap/view.xml.twig")
21
     *
22
     * @param $locale
23
     *
24
     * @return array
25
     */
26
    public function sitemapAction($locale)
27
    {
28
        $nodeMenu = $this->get('kunstmaan_node.node_menu');
29
        $nodeMenu->setLocale($locale);
30
        $nodeMenu->setIncludeOffline(false);
31
        $nodeMenu->setIncludeHiddenFromNav(true);
32
        $nodeMenu->setCurrentNode(null);
33
34
        $event = new PreSitemapRenderEvent($locale);
35
        $this->get('event_dispatcher')->dispatch(PreSitemapRenderEvent::NAME, $event);
36
37
        return [
38
            'nodemenu' => $nodeMenu,
39
            'locale' => $locale,
40
            'extraItems' => $event->getExtraItems(),
41
        ];
42
    }
43
44
    /**
45
     * This will generate a sitemap index file to define a sub sitemap for each
46
     * language. Info at:
47
     * https://support.google.com/webmasters/answer/75712?rd=1 Use the mode
48
     * parameter to select in which mode the sitemap should be generated. At
49
     * this moment only XML is supported
50
     *
51
     * @Route("/sitemap.{_format}", name="KunstmaanSitemapBundle_sitemapindex",
52
     *                              requirements={"_format" = "xml"})
53
     * @Template("@KunstmaanSitemap/SitemapIndex/view.xml.twig")
54
     *
55
     * @return array
56
     */
57
    public function sitemapIndexAction(Request $request)
58
    {
59
        $locales = $this->get('kunstmaan_admin.domain_configuration')
60
            ->getBackendLocales();
61
62
        return [
63
            'locales' => $locales,
64
            'host' => $request->getSchemeAndHttpHost(),
65
        ];
66
    }
67
}
68