diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 42e4d067..a2b789af 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -63,6 +63,10 @@ public function getConfigTreeBuilder() ->scalarNode('lastmod')->defaultValue('now')->end() ->end() ->end() + ->scalarNode('default_section') + ->defaultValue('default') + ->info('The default section in which static routes are registered.') + ->end() ->end() ; diff --git a/DependencyInjection/PrestaSitemapExtension.php b/DependencyInjection/PrestaSitemapExtension.php index 93fbf5f6..fc9bc992 100644 --- a/DependencyInjection/PrestaSitemapExtension.php +++ b/DependencyInjection/PrestaSitemapExtension.php @@ -36,6 +36,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter($this->getAlias() . '.sitemap_file_prefix', $config['sitemap_file_prefix']); $container->setParameter($this->getAlias() . '.items_by_set', $config['items_by_set']); $container->setParameter($this->getAlias() . '.defaults', $config['defaults']); + $container->setParameter($this->getAlias() . '.default_section', $config['default_section']); if (true === $config['route_annotation_listener']) { $loader->load('route_annotation_listener.xml'); diff --git a/EventListener/RouteAnnotationEventListener.php b/EventListener/RouteAnnotationEventListener.php index ed58eb7b..f95938b1 100644 --- a/EventListener/RouteAnnotationEventListener.php +++ b/EventListener/RouteAnnotationEventListener.php @@ -42,12 +42,19 @@ class RouteAnnotationEventListener implements EventSubscriberInterface */ protected $router; + /** + * @var string + */ + private $defaultSection; + /** * @param RouterInterface $router + * @param string $defaultSection */ - public function __construct(RouterInterface $router) + public function __construct(RouterInterface $router, $defaultSection) { $this->router = $router; + $this->defaultSection = $defaultSection; } /** @@ -67,7 +74,7 @@ public function registerRouteAnnotation(SitemapPopulateEvent $event) { $section = $event->getSection(); - if (is_null($section) || $section == 'default') { + if (is_null($section) || $section === $this->defaultSection) { $this->addUrlsFromRoutes($event); } } @@ -89,7 +96,7 @@ private function addUrlsFromRoutes(SitemapPopulateEvent $event) continue; } - $section = $event->getSection() ?: 'default'; + $section = $event->getSection() ?: $this->defaultSection; if (isset($options['section'])) { $section = $options['section']; } diff --git a/Resources/config/route_annotation_listener.xml b/Resources/config/route_annotation_listener.xml index 987d5b00..c045fcd4 100644 --- a/Resources/config/route_annotation_listener.xml +++ b/Resources/config/route_annotation_listener.xml @@ -10,6 +10,7 @@ + %presta_sitemap.default_section% diff --git a/Resources/doc/2-configuration.md b/Resources/doc/2-configuration.md index 56ff5a20..c4d86353 100644 --- a/Resources/doc/2-configuration.md +++ b/Resources/doc/2-configuration.md @@ -13,6 +13,14 @@ presta_sitemap: lastmod: now ``` +Or choose the default sections for static routes: + +```yaml +# config/packages/presta_sitemap.yaml +presta_sitemap: + default_section: default +``` + ## Time to live You may want to change the default `3600` seconds max-age set when rendering the diff --git a/Resources/doc/3-static-routes-usage.md b/Resources/doc/3-static-routes-usage.md index 60b60220..bd926e2a 100644 --- a/Resources/doc/3-static-routes-usage.md +++ b/Resources/doc/3-static-routes-usage.md @@ -11,6 +11,9 @@ The supported sitemap parameters are: one of `"always"`, `"hourly"`, `"daily"`, `"weekly"`, `"monthly"`, `"yearly"`, `"never"` (default: `"daily"`) * `"priority"`: a number between `0` and `1` (default: `1`) +> **Note** you can change defaults in the bundle configuration. +> Jump to [dedicated documentation](2-configuration.md) for more information. + ## Annotation diff --git a/Tests/EventListener/RouteAnnotationEventListenerTest.php b/Tests/EventListener/RouteAnnotationEventListenerTest.php index f555ffec..311c9a38 100644 --- a/Tests/EventListener/RouteAnnotationEventListenerTest.php +++ b/Tests/EventListener/RouteAnnotationEventListenerTest.php @@ -130,15 +130,9 @@ private function getRouter() */ private function getListener() { - $listener = new RouteAnnotationEventListener( + return new RouteAnnotationEventListener( $this->getRouter(), - array( - 'priority' => 1, - 'changefreq' => UrlConcrete::CHANGEFREQ_DAILY, - 'lastmod' => 'now', - ) + 'default' ); - - return $listener; } }