1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\SitemapBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\SitemapBundle\Event\PreSitemapRenderEvent; |
6
|
|
|
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; |
7
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
|
12
|
|
|
class SitemapController extends Controller |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* This will generate a sitemap for the specified locale. |
16
|
|
|
* Use the mode parameter to select in which mode the sitemap should be |
17
|
|
|
* generated. At this moment only XML is supported |
18
|
|
|
* |
19
|
|
|
* @Route("/sitemap-{locale}.{_format}", name="KunstmaanSitemapBundle_sitemap", |
20
|
|
|
* requirements={"_format" = "xml"}) |
21
|
|
|
* @Template("@KunstmaanSitemap/Sitemap/view.xml.twig") |
22
|
|
|
* |
23
|
|
|
* @param $locale |
24
|
|
|
* |
25
|
|
|
* @return array |
26
|
|
|
*/ |
27
|
|
|
public function sitemapAction($locale) |
28
|
|
|
{ |
29
|
|
|
$nodeMenu = $this->get('kunstmaan_node.node_menu'); |
30
|
|
|
$nodeMenu->setLocale($locale); |
31
|
|
|
$nodeMenu->setIncludeOffline(false); |
32
|
|
|
$nodeMenu->setIncludeHiddenFromNav(true); |
33
|
|
|
$nodeMenu->setCurrentNode(null); |
34
|
|
|
|
35
|
|
|
$event = new PreSitemapRenderEvent($locale); |
36
|
|
|
$this->dispatch($event, PreSitemapRenderEvent::NAME); |
37
|
|
|
|
38
|
|
|
return array( |
39
|
|
|
'nodemenu' => $nodeMenu, |
40
|
|
|
'locale' => $locale, |
41
|
|
|
'extraItems' => $event->getExtraItems(), |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* This will generate a sitemap index file to define a sub sitemap for each |
47
|
|
|
* language. Info at: |
48
|
|
|
* https://support.google.com/webmasters/answer/75712?rd=1 Use the mode |
49
|
|
|
* parameter to select in which mode the sitemap should be generated. At |
50
|
|
|
* this moment only XML is supported |
51
|
|
|
* |
52
|
|
|
* @Route("/sitemap.{_format}", name="KunstmaanSitemapBundle_sitemapindex", |
53
|
|
|
* requirements={"_format" = "xml"}) |
54
|
|
|
* @Template("@KunstmaanSitemap/SitemapIndex/view.xml.twig") |
55
|
|
|
* |
56
|
|
|
* @param Request $request |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
public function sitemapIndexAction(Request $request) |
61
|
|
|
{ |
62
|
|
|
$locales = $this->get('kunstmaan_admin.domain_configuration') |
63
|
|
|
->getBackendLocales(); |
64
|
|
|
|
65
|
|
|
return array( |
66
|
|
|
'locales' => $locales, |
67
|
|
|
'host' => $request->getSchemeAndHttpHost(), |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param object $event |
73
|
|
|
* @param string $eventName |
74
|
|
|
* |
75
|
|
|
* @return object |
76
|
|
|
*/ |
77
|
|
View Code Duplication |
private function dispatch($event, string $eventName) |
78
|
|
|
{ |
79
|
|
|
$eventDispatcher = $this->container->get('event_dispatcher'); |
80
|
|
|
if (class_exists(LegacyEventDispatcherProxy::class)) { |
81
|
|
|
$eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); |
82
|
|
|
|
83
|
|
|
return $eventDispatcher->dispatch($event, $eventName); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $eventDispatcher->dispatch($eventName, $event); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.