|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Ivory Google Map bundle package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Ivory\GoogleMapBundle\Twig; |
|
15
|
|
|
|
|
16
|
|
|
use Ivory\GoogleMap\Helper\PlaceAutocompleteHelper; |
|
17
|
|
|
use Ivory\GoogleMap\Place\Autocomplete; |
|
18
|
|
|
use Twig\Extension\AbstractExtension; |
|
19
|
|
|
use Twig\TwigFunction; |
|
20
|
|
|
|
|
21
|
|
|
class PlaceAutocompleteExtension extends AbstractExtension |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var PlaceAutocompleteHelper */ |
|
24
|
|
|
private $placeAutocompleteHelper; |
|
25
|
|
|
|
|
26
|
3 |
|
public function __construct(PlaceAutocompleteHelper $placeAutocompleteHelper) |
|
27
|
|
|
{ |
|
28
|
3 |
|
$this->placeAutocompleteHelper = $placeAutocompleteHelper; |
|
29
|
3 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** {@inheritdoc} */ |
|
32
|
3 |
|
public function getFunctions(): array |
|
33
|
|
|
{ |
|
34
|
3 |
|
$functions = []; |
|
35
|
|
|
|
|
36
|
3 |
|
foreach ($this->getMapping() as $name => $method) { |
|
37
|
3 |
|
$functions[] = new TwigFunction($name, [$this, $method], ['is_safe' => ['html']]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
3 |
|
return $functions; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
public function render(Autocomplete $autocomplete, array $attributes = []): string |
|
44
|
|
|
{ |
|
45
|
1 |
|
$autocomplete->addInputAttributes($attributes); |
|
46
|
|
|
|
|
47
|
1 |
|
return $this->placeAutocompleteHelper->render($autocomplete); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function renderHtml(Autocomplete $autocomplete, array $attributes = []): string |
|
51
|
|
|
{ |
|
52
|
1 |
|
$autocomplete->addInputAttributes($attributes); |
|
53
|
|
|
|
|
54
|
1 |
|
return $this->placeAutocompleteHelper->renderHtml($autocomplete); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
public function renderJavascript(Autocomplete $autocomplete): string |
|
58
|
|
|
{ |
|
59
|
1 |
|
return $this->placeAutocompleteHelper->renderJavascript($autocomplete); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getName(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return 'ivory_google_place_autocomplete'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
3 |
|
private function getMapping(): array |
|
68
|
|
|
{ |
|
69
|
|
|
return [ |
|
70
|
3 |
|
'ivory_google_place_autocomplete' => 'render', |
|
71
|
|
|
'ivory_google_place_autocomplete_container' => 'renderHtml', |
|
72
|
|
|
'ivory_google_place_autocomplete_js' => 'renderJavascript', |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|