|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Sulu. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) MASSIVE ART WebServices GmbH |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sulu\Bundle\ArticleBundle\Admin; |
|
13
|
|
|
|
|
14
|
|
|
use Sulu\Bundle\AdminBundle\Admin\JsConfigInterface; |
|
15
|
|
|
use Sulu\Bundle\ArticleBundle\Metadata\StructureTagTrait; |
|
16
|
|
|
use Sulu\Component\Content\Compat\StructureManagerInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Provides js-configuration. |
|
20
|
|
|
*/ |
|
21
|
|
|
class ArticleJsConfig implements JsConfigInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use StructureTagTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var StructureManagerInterface |
|
27
|
|
|
*/ |
|
28
|
|
|
private $structureManager; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private $typeConfiguration; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var bool |
|
37
|
|
|
*/ |
|
38
|
|
|
private $displayTabAll; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param StructureManagerInterface $structureManager |
|
42
|
|
|
* @param array $typeConfiguration |
|
43
|
|
|
* @param bool $displayTabAll |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
StructureManagerInterface $structureManager, |
|
47
|
|
|
array $typeConfiguration, |
|
48
|
|
|
$displayTabAll |
|
49
|
|
|
) { |
|
50
|
|
|
$this->structureManager = $structureManager; |
|
51
|
|
|
$this->typeConfiguration = $typeConfiguration; |
|
52
|
|
|
$this->displayTabAll = $displayTabAll; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getParameters() |
|
59
|
|
|
{ |
|
60
|
|
|
$config = [ |
|
61
|
|
|
'types' => [], |
|
62
|
|
|
'templates' => [], |
|
63
|
|
|
'displayTabAll' => $this->displayTabAll, |
|
64
|
|
|
]; |
|
65
|
|
|
|
|
66
|
|
|
foreach ($this->structureManager->getStructures('article') as $structure) { |
|
67
|
|
|
$type = $this->getType($structure->getStructure()); |
|
|
|
|
|
|
68
|
|
|
if (!array_key_exists($type, $config['types'])) { |
|
69
|
|
|
$config['types'][$type] = [ |
|
70
|
|
|
'default' => $structure->getKey(), |
|
71
|
|
|
'title' => $this->getTitle($type), |
|
72
|
|
|
]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$config['templates'][$structure->getKey()] = [ |
|
76
|
|
|
'multipage' => ['enabled' => $this->getMultipage($structure->getStructure())], |
|
|
|
|
|
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $config; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* {@inheritdoc} |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getName() |
|
87
|
|
|
{ |
|
88
|
|
|
return 'sulu_article'; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Returns title for given type. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $type |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
private function getTitle($type) |
|
99
|
|
|
{ |
|
100
|
|
|
if (!array_key_exists($type, $this->typeConfiguration)) { |
|
101
|
|
|
return ucfirst($type); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this->typeConfiguration[$type]['translation_key']; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: