1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Everlution\AjaxcomBundle\Controller; |
||
6 | |||
7 | use Everlution\AjaxcomBundle\DataObject\Callback; |
||
8 | use Everlution\AjaxcomBundle\Service\Ajaxcom; |
||
9 | use Symfony\Component\HttpFoundation\Response; |
||
10 | |||
11 | /** |
||
12 | * Class BaseController. |
||
13 | * |
||
14 | * @author Ivan Barlog <[email protected]> |
||
15 | * |
||
16 | * The trait expects you provide a get($service) method, |
||
17 | * for example via Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait |
||
18 | */ |
||
19 | trait AjaxcomTrait |
||
20 | { |
||
21 | public function render($view, array $parameters = array(), Response $response = null): Response |
||
22 | { |
||
23 | $request = $this->get('request_stack')->getMasterRequest(); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
24 | |||
25 | if ($request->server->get(Ajaxcom::AJAX_COM_HEADER, false)) { |
||
26 | return $this->get('ajaxcom.handler')->handle($view, $parameters); |
||
27 | } |
||
28 | |||
29 | return parent::render($view, $parameters, $response); |
||
30 | } |
||
31 | |||
32 | protected function replaceBlockContent(string $selector, string $blockId): self |
||
33 | { |
||
34 | $this->get('ajaxcom.mutation.replace_content')->add($selector, $blockId); |
||
35 | |||
36 | return $this; |
||
37 | } |
||
38 | |||
39 | protected function renderAjaxBlock(string $id): self |
||
40 | { |
||
41 | $this->get('ajaxcom.mutation.add_blocks')->add($id); |
||
42 | |||
43 | return $this; |
||
44 | } |
||
45 | |||
46 | protected function refreshAjaxBlock(string $id): self |
||
47 | { |
||
48 | $this->get('ajaxcom.mutation.add_blocks')->refresh($id); |
||
49 | |||
50 | return $this; |
||
51 | } |
||
52 | |||
53 | protected function removeAjaxBlock(string $selector): self |
||
54 | { |
||
55 | $this->get('ajaxcom.mutation.remove_blocks')->add($selector); |
||
56 | |||
57 | return $this; |
||
58 | } |
||
59 | |||
60 | protected function addCallback(string $functionName, array $parameters = []): self |
||
61 | { |
||
62 | $this->get('ajaxcom.mutation.callbacks')->add(new Callback($functionName, $parameters)); |
||
63 | |||
64 | return $this; |
||
65 | } |
||
66 | |||
67 | protected function replaceClass(string $selector, string $class): self |
||
68 | { |
||
69 | $this->get('ajaxcom.mutation.replace_class')->add($selector, $class); |
||
70 | |||
71 | return $this; |
||
72 | } |
||
73 | |||
74 | protected function doNotChangeUrl(): self |
||
75 | { |
||
76 | $this->get('ajaxcom.mutation.change_url')->doNotChangeUrl(); |
||
77 | |||
78 | return $this; |
||
79 | } |
||
80 | |||
81 | protected function appendAjaxBlock(string $id): self |
||
82 | { |
||
83 | $this->get('ajaxcom.mutation.append_blocks')->add($id); |
||
84 | |||
85 | return $this; |
||
86 | } |
||
87 | |||
88 | protected function prependAjaxBlock(string $id): self |
||
89 | { |
||
90 | $this->get('ajaxcom.mutation.prepend_blocks')->add($id); |
||
91 | |||
92 | return $this; |
||
93 | } |
||
94 | } |
||
95 |