1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\CmsBundle\Controller\Admin; |
14
|
|
|
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
use WellCommerce\Bundle\AppBundle\Entity\LayoutBox; |
18
|
|
|
use WellCommerce\Bundle\CmsBundle\Entity\Page; |
19
|
|
|
use WellCommerce\Bundle\CoreBundle\Controller\Admin\AbstractAdminController; |
20
|
|
|
use WellCommerce\Bundle\CoreBundle\Helper\Helper; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class PageController |
24
|
|
|
* |
25
|
|
|
* @author Adam Piotrowski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class PageController extends AbstractAdminController |
28
|
|
|
{ |
29
|
|
|
public function editLayoutAction(Page $page): Response |
30
|
|
|
{ |
31
|
|
|
$boxes = []; |
32
|
|
|
$layoutBoxes = $this->get('layout_box.repository')->getCollection(); |
33
|
|
|
$layoutBoxes->map(function (LayoutBox $layoutBox) use (&$boxes) { |
34
|
|
|
list($type,) = explode('_', Helper::snake($layoutBox->getBoxType())); |
35
|
|
|
|
36
|
|
|
$boxes[$type][$layoutBox->getIdentifier()] = $layoutBox->translate()->getName(); |
37
|
|
|
}); |
38
|
|
|
|
39
|
|
|
ksort($boxes); |
40
|
|
|
|
41
|
|
|
return $this->displayTemplate('edit_layout', [ |
42
|
|
|
'resource' => $page, |
43
|
|
|
'boxes' => $boxes, |
44
|
|
|
'form' => $this->getPageLayoutForm(), |
45
|
|
|
]); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function saveLayoutAction(Page $page, Request $request): Response |
49
|
|
|
{ |
50
|
|
|
$page->setLayout($request->get('layout')); |
51
|
|
|
$this->manager->updateResource($page); |
52
|
|
|
|
53
|
|
|
return $this->jsonResponse([ |
54
|
|
|
'success' => true, |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function getPageLayoutForm() |
59
|
|
|
{ |
60
|
|
|
return $this->get('page_layout.form_builder.admin')->createForm(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|