Skip to content

Commit

Permalink
Merge pull request #3 from stephskuola/master
Browse files Browse the repository at this point in the history
Bad GET parameters removed from meta next and prev tags.
  • Loading branch information
fabiocicerchia authored Apr 18, 2017
2 parents f041d6e + f88fa5a commit 49d8aa4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor/
.idea
37 changes: 31 additions & 6 deletions Extension/Twig/PaginationMetaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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('<link rel="%s" href="%s">',
$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
*/
Expand Down
3 changes: 2 additions & 1 deletion Resources/config/parameters.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
parameters:
skuola_seo.twig_pagination_meta.extension.class: OpenSkuola\SeoBundle\Extension\Twig\PaginationMetaExtension
skuola_seo.twig_pagination_meta.extension.class: OpenSkuola\SeoBundle\Extension\Twig\PaginationMetaExtension
skuola_seo.bad_route_info_params: ["direction", "sort"]
2 changes: 1 addition & 1 deletion Resources/config/twig.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 49d8aa4

Please sign in to comment.