|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher Core Bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please see the |
|
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @copyright 2015 Sourcefabric z.ú |
|
12
|
|
|
* @license http://www.superdesk.org/license |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace SWP\Bundle\CoreBundle\Routing; |
|
16
|
|
|
|
|
17
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleInterface; |
|
18
|
|
|
use SWP\Bundle\ContentBundle\Model\RouteInterface; |
|
19
|
|
|
use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter; |
|
20
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Meta\Meta; |
|
21
|
|
|
|
|
22
|
|
|
class MetaRouter extends DynamicRouter |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
66 |
|
public function generate($name, $parameters = [], $referenceType = false) |
|
28
|
|
|
{ |
|
29
|
66 |
|
$route = $name; |
|
30
|
66 |
|
if (is_object($name) && $name->getValues() instanceof ArticleInterface) { |
|
31
|
4 |
|
$parameters['slug'] = $name->getValues()->getSlug(); |
|
32
|
4 |
|
$route = $name->getValues()->getRoute(); |
|
33
|
|
|
|
|
34
|
4 |
|
if (null === $route && $name->getContext()->getCurrentPage()) { |
|
35
|
1 |
|
$parameters['slug'] = null; |
|
36
|
4 |
|
$route = $name->getContext()->getCurrentPage()->getValues(); |
|
37
|
|
|
} |
|
38
|
62 |
|
} elseif (is_object($name) && $name->getValues() instanceof RouteInterface) { |
|
39
|
|
|
$route = $name->getValues(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
66 |
|
return parent::generate($route, $parameters, $referenceType); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
66 |
|
public function supports($name) |
|
49
|
|
|
{ |
|
50
|
66 |
|
return $name instanceof Meta && ( |
|
51
|
3 |
|
$name->getValues() instanceof ArticleInterface || |
|
52
|
3 |
|
$name->getValues() instanceof RouteInterface |
|
53
|
66 |
|
) || is_string($name); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|