1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Superdesk Web Publisher Content Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Sourcefabric z.ú. 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 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\ContentBundle\Routing; |
16
|
|
|
|
17
|
|
|
use SWP\Bundle\ContentBundle\Model\ArticleMedia; |
18
|
|
|
use SWP\Bundle\ContentBundle\Model\FileInterface; |
19
|
|
|
use SWP\Bundle\ContentBundle\Model\ImageInterface; |
20
|
|
|
use SWP\Bundle\ContentBundle\Model\ImageRendition; |
21
|
|
|
use SWP\Component\TemplatesSystem\Gimme\Meta\Meta; |
22
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\Router; |
23
|
|
|
use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface; |
24
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
25
|
|
|
|
26
|
|
|
class MediaRouter extends Router implements VersatileGeneratorInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
1 |
|
public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH) |
32
|
|
|
{ |
33
|
1 |
|
if (null === $item = $this->getItem($name)) { |
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
$parameters['mediaId'] = $item->getId(); |
38
|
1 |
|
$parameters['extension'] = $item->getFileExtension(); |
39
|
|
|
|
40
|
1 |
|
return parent::generate('swp_media_get', $parameters, $referenceType); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
66 |
|
public function supports($name) |
47
|
|
|
{ |
48
|
66 |
|
return $name instanceof Meta && ($name->getValues() instanceof ArticleMedia || $name->getValues() instanceof ImageRendition); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function getRouteDebugMessage($name, array $parameters = array()) |
55
|
|
|
{ |
56
|
|
|
return 'Route for media '.$name->getValues()->getId().' not found'; |
57
|
|
|
} |
58
|
|
|
|
59
|
1 |
|
private function getItem($name) |
60
|
|
|
{ |
61
|
1 |
|
$values = $name->getValues(); |
62
|
1 |
|
if ($name->getValues() instanceof ImageRendition) { |
63
|
|
|
return $name->getValues()->getImage(); |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
if ($values->getImage() instanceof ImageInterface) { |
67
|
1 |
|
return $values->getImage(); |
68
|
|
|
} elseif ($values->getFile() instanceof FileInterface) { |
69
|
|
|
return $values->getFile(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|