diff --git a/.gitignore b/.gitignore index 48b8bf9..31e3ac6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ vendor/ +.idea diff --git a/Extension/Twig/PaginationMetaExtension.php b/Extension/Twig/PaginationMetaExtension.php index 5194682..df2c417 100644 --- a/Extension/Twig/PaginationMetaExtension.php +++ b/Extension/Twig/PaginationMetaExtension.php @@ -3,6 +3,7 @@ namespace OpenSkuola\SeoBundle\Extension\Twig; use Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\RouterInterface; @@ -33,12 +34,18 @@ class PaginationMetaExtension extends \Twig_Extension */ protected $accessor; + /** + * @var array + */ + protected $badRouteInfoParams; + /** * PaginationMetaExtension constructor. * @param RouterInterface $router */ - public function __construct(RouterInterface $router) + public function __construct(RouterInterface $router, array $badRouteInfoParams) { + $this->badRouteInfoParams = $badRouteInfoParams; $this->router = $router; $this->accessor = PropertyAccess::createPropertyAccessor(); } @@ -127,16 +134,34 @@ function($parameter) use (&$routeInfo, $request) { ); } + $routeInfo['params'] = $this->cleanRouteInfoParams($routeInfo['params']); + + $generatedUrl = $this->router->generate( + $routeInfo['name'], + $routeInfo['params'], + UrlGenerator::ABSOLUTE_URL + ); + return sprintf('', $direction, - $this->router->generate( - $routeInfo['name'], - $routeInfo['params'], - UrlGenerator::ABSOLUTE_URL - ) + $generatedUrl ); } + /** + * @param array + * @return array + */ + public function cleanRouteInfoParams($routeInfoParams) + { + foreach($this->badRouteInfoParams as $badParam) + { + if(isset($routeInfoParams[$badParam])) unset($routeInfoParams[$badParam]); + } + + return $routeInfoParams; + } + /** * @return RequestStack */ diff --git a/Resources/config/parameters.yml b/Resources/config/parameters.yml index 582aadd..59d6139 100644 --- a/Resources/config/parameters.yml +++ b/Resources/config/parameters.yml @@ -1,2 +1,3 @@ parameters: - skuola_seo.twig_pagination_meta.extension.class: OpenSkuola\SeoBundle\Extension\Twig\PaginationMetaExtension \ No newline at end of file + skuola_seo.twig_pagination_meta.extension.class: OpenSkuola\SeoBundle\Extension\Twig\PaginationMetaExtension + skuola_seo.bad_route_info_params: ["direction", "sort"] diff --git a/Resources/config/twig.yml b/Resources/config/twig.yml index ef10c92..5963623 100644 --- a/Resources/config/twig.yml +++ b/Resources/config/twig.yml @@ -1,7 +1,7 @@ services: skuola_seo.twig_pagination_meta.extension: class: "%skuola_seo.twig_pagination_meta.extension.class%" - arguments: [ "@router"] + arguments: [ "@router", "%skuola_seo.bad_route_info_params%"] calls: - [setRequestStack, [ "@request_stack" ]] tags: