|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MediaMonks\SonataMediaBundle\Form\Type; |
|
4
|
|
|
|
|
5
|
|
|
use MediaMonks\SonataMediaBundle\Admin\MediaAdmin; |
|
6
|
|
|
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType as BaseModelAutocompleteType; |
|
7
|
|
|
use Symfony\Component\OptionsResolver\Options; |
|
8
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
9
|
|
|
use Twig\Environment; |
|
10
|
|
|
|
|
11
|
|
|
class MediaAutocompleteType extends BaseModelAutocompleteType |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var MediaAdmin |
|
15
|
|
|
*/ |
|
16
|
|
|
private $mediaAdmin; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var Environment |
|
20
|
|
|
*/ |
|
21
|
|
|
private $twig; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param MediaAdmin $mediaAdmin |
|
25
|
|
|
* @param Environment $twig |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function __construct(MediaAdmin $mediaAdmin, Environment $twig) |
|
28
|
|
|
{ |
|
29
|
1 |
|
$this->mediaAdmin = $mediaAdmin; |
|
30
|
1 |
|
$this->twig = $twig; |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param OptionsResolver $resolver |
|
35
|
|
|
*/ |
|
36
|
1 |
|
public function configureOptions(OptionsResolver $resolver) |
|
37
|
|
|
{ |
|
38
|
1 |
|
parent::configureOptions($resolver); |
|
39
|
|
|
|
|
40
|
|
|
// Tell sonata we are passing a previously escaped string |
|
41
|
1 |
|
if ($resolver->hasDefault('safe_label')) { |
|
42
|
1 |
|
$resolver->setDefault('safe_label', true); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
$resolver->setDefaults( |
|
46
|
|
|
[ |
|
47
|
1 |
|
'type' => null, |
|
48
|
|
|
'provider' => null, |
|
49
|
1 |
|
'property' => 'title', |
|
50
|
1 |
|
'to_string_callback' => function ($media, $property) { |
|
|
|
|
|
|
51
|
|
|
return $this->twig->render( |
|
52
|
|
|
'@MediaMonksSonataMedia/CRUD/autocomplete.html.twig', |
|
53
|
|
|
[ |
|
54
|
|
|
'media' => $media, |
|
55
|
|
|
] |
|
56
|
|
|
); |
|
57
|
1 |
|
}, |
|
58
|
1 |
|
'route' => function(Options $options) { |
|
59
|
1 |
|
$parameters = []; |
|
60
|
1 |
|
if (isset($options['type'])) { |
|
61
|
1 |
|
$parameters['type'] = $options['type']; |
|
62
|
|
|
} |
|
63
|
1 |
|
if (isset($options['provider'])) { |
|
64
|
1 |
|
$parameters['provider'] = $options['provider']; |
|
65
|
|
|
} |
|
66
|
1 |
|
return ['name' => 'mediamonks_media_autocomplete', 'parameters' => $parameters]; |
|
67
|
1 |
|
}, |
|
68
|
1 |
|
'model_manager' => $this->mediaAdmin->getModelManager() |
|
69
|
|
|
] |
|
70
|
|
|
); |
|
71
|
1 |
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.