|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Boudewijn Schoon <[email protected]> |
|
4
|
|
|
* @copyright Zicht Online <http://zicht.nl> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Zicht\Bundle\UrlBundle\Admin; |
|
8
|
|
|
|
|
9
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
10
|
|
|
use Symfony\Component\Form\AbstractType; |
|
11
|
|
|
use Symfony\Component\Form\FormInterface; |
|
12
|
|
|
use Symfony\Component\Form\FormView; |
|
13
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
14
|
|
|
use Zicht\Bundle\UrlBundle\Entity\UrlAlias; |
|
15
|
|
|
use Zicht\Bundle\UrlBundle\Exception\UnsupportedException; |
|
16
|
|
|
use Zicht\Bundle\UrlBundle\Url\Provider; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Form type to render all available url aliases |
|
20
|
|
|
*/ |
|
21
|
|
|
class AliasOverviewType extends AbstractType |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var Provider */ |
|
24
|
|
|
protected $provider; |
|
25
|
|
|
|
|
26
|
|
|
/** @var RegistryInterface */ |
|
27
|
|
|
protected $doctrine; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* AliasOverviewType constructor. |
|
31
|
|
|
* |
|
32
|
|
|
* @param Provider $provider |
|
33
|
|
|
* @param RegistryInterface $doctrine |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(Provider $provider, RegistryInterface $doctrine) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->provider = $provider; |
|
38
|
|
|
$this->doctrine = $doctrine; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @{inheritDoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
45
|
|
|
{ |
|
46
|
|
|
parent::configureOptions($resolver); |
|
47
|
|
|
$resolver->setRequired('record'); |
|
48
|
|
|
$resolver->setDefaults( |
|
49
|
|
|
[ |
|
50
|
|
|
'translation_domain' => 'admin', |
|
51
|
|
|
'label' => 'admin.alias_overview_admin.label', |
|
52
|
|
|
'required' => false, |
|
53
|
|
|
'virtual' => true, |
|
54
|
|
|
] |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @{inheritDoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options) |
|
62
|
|
|
{ |
|
63
|
|
|
parent::buildView($view, $form, $options); |
|
64
|
|
|
$aliases = $this->getUrlAliases($options['record']); |
|
65
|
|
|
$view->vars['record'] = $options['record']; |
|
66
|
|
|
$view->vars['url_aliases'] = $aliases; |
|
67
|
|
|
$view->vars['url_aliases_grouped'] = $this->groupByMode($aliases); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param UrlAlias[] $aliases |
|
72
|
|
|
* @return array|UrlAlias[][] |
|
73
|
|
|
*/ |
|
74
|
|
|
private function groupByMode($aliases) |
|
75
|
|
|
{ |
|
76
|
|
|
$property = new \ReflectionProperty(UrlAlias::class, 'mode'); |
|
77
|
|
|
$property->setAccessible(true); |
|
78
|
|
|
$grouped = []; |
|
79
|
|
|
foreach ($aliases as $alias) { |
|
80
|
|
|
$grouped[$property->getValue($alias)][] = $alias; |
|
81
|
|
|
} |
|
82
|
|
|
return $grouped; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns all UrlAlias entities associated to an object |
|
87
|
|
|
* |
|
88
|
|
|
* @param mixed $object |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function getUrlAliases($object) |
|
91
|
|
|
{ |
|
92
|
|
|
try { |
|
93
|
|
|
$internalUrl = $this->provider->url($object); |
|
94
|
|
|
} catch (UnsupportedException $exception) { |
|
95
|
|
|
return []; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this |
|
99
|
|
|
->doctrine |
|
100
|
|
|
->getRepository('ZichtUrlBundle:UrlAlias') |
|
101
|
|
|
->findAllByInternalUrl($internalUrl); |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @{inheritDoc} |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getName() |
|
108
|
|
|
{ |
|
109
|
|
|
return 'alias_overview_type'; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* {@inheritDoc} |
|
114
|
|
|
*/ |
|
115
|
|
|
public function getBlockPrefix() |
|
116
|
|
|
{ |
|
117
|
|
|
return 'alias_overview_type'; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.