1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\ArticleBundle\Router; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\NodeBundle\Router\SlugRouter; |
6
|
|
|
use Symfony\Component\Routing\RouteCollection; |
7
|
|
|
use Symfony\Component\Translation\TranslatorInterface; |
8
|
|
|
|
9
|
|
|
class TagCategoryRouter extends SlugRouter |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @return \Symfony\Component\Routing\RouteCollection |
13
|
|
|
*/ |
14
|
|
|
public function getRouteCollection() |
15
|
|
|
{ |
16
|
|
|
if (!\is_null($this->routeCollection)) { |
17
|
|
|
return $this->routeCollection; |
18
|
|
|
} |
19
|
|
|
$this->routeCollection = new RouteCollection(); |
20
|
|
|
|
21
|
|
|
$extendParameters = array('category' => null, 'tag' => null); |
22
|
|
|
$baseSlugParameters = array_merge($this->getSlugRouteParameters(), $extendParameters); |
23
|
|
|
$baseSlugPreviewParameters = array_merge($this->getPreviewRouteParameters(), $extendParameters); |
24
|
|
|
|
25
|
|
|
/** @var TranslatorInterface $translator */ |
26
|
|
|
$translator = $this->container->get('translator'); |
|
|
|
|
27
|
|
|
|
28
|
|
|
if ($this->isMultiLanguage()) { |
29
|
|
|
foreach ($this->getFrontendLocales() as $locale) { |
30
|
|
|
$categoryTrans = $translator->trans('article_overview_page.route.category', [], null, $locale); |
31
|
|
|
$tagTrans = $translator->trans('article_overview_page.route.tag', [], null, $locale); |
32
|
|
|
|
33
|
|
|
$routePathParts = array( |
34
|
|
|
'_slug_category_tag' => sprintf('/%s/{category}/%s/{tag}', $categoryTrans, $tagTrans), |
35
|
|
|
'_slug_tag' => sprintf('/%s/{tag}', $tagTrans), |
36
|
|
|
'_slug_category' => sprintf('/%s/{category}', $categoryTrans), |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
foreach ($routePathParts as $routeName => $routePart) { |
40
|
|
|
$slugParameters = $baseSlugParameters; |
41
|
|
|
$slugParameters['path'] = '/{_locale}/{url}' . $routePart; |
42
|
|
|
|
43
|
|
|
$slugPreviewParameters = $baseSlugPreviewParameters; |
44
|
|
|
$slugPreviewParameters['path'] = '/{_locale}/admin/preview/{url}' . $routePart; |
45
|
|
|
|
46
|
|
|
$routeName .= '_' . $locale; |
47
|
|
|
$this->addRoute($routeName . '_preview', $slugPreviewParameters); |
48
|
|
|
$this->addRoute($routeName, $slugParameters); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} else { |
52
|
|
|
$categoryTrans = $translator->trans('article_overview_page.route.category'); |
53
|
|
|
$tagTrans = $translator->trans('article_overview_page.route.tag'); |
54
|
|
|
|
55
|
|
|
$slugParameters = $baseSlugParameters; |
56
|
|
|
$slugPreviewParameters = $baseSlugPreviewParameters; |
57
|
|
|
|
58
|
|
|
$routePathParts = array( |
59
|
|
|
'_slug_category_tag' => sprintf('/%s/{category}/%s/{tag}', $categoryTrans, $tagTrans), |
60
|
|
|
'_slug_tag' => sprintf('/%s/{tag}', $tagTrans), |
61
|
|
|
'_slug_category' => sprintf('/%s/{category}', $categoryTrans), |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
foreach ($routePathParts as $routeName => $routePart) { |
65
|
|
|
$slugParameters['path'] = '/{url}' . $routePart; |
66
|
|
|
$slugPreviewParameters['path'] = '/admin/preview/{url}' . $routePart; |
67
|
|
|
|
68
|
|
|
$this->addRoute($routeName . '_preview', $slugPreviewParameters); |
69
|
|
|
$this->addRoute($routeName, $slugParameters); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->routeCollection; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.