/
edit.php
74 lines (64 loc) · 2.46 KB
/
edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Concrete\Controller\Dialog\Block;
use Concrete\Controller\Backend\UserInterface\Block as BackendInterfaceBlockController;
use Concrete\Core\Block\Block;
use Concrete\Core\Block\Events\BlockEdit;
use Concrete\Core\Block\View\BlockView;
use Concrete\Core\Support\Facade\Events;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Error\ErrorList\ErrorList;
use Concrete\Core\Error\ErrorList\Formatter\JsonFormatter;
use Concrete\Core\Http\ResponseFactoryInterface;
class Edit extends BackendInterfaceBlockController
{
protected $viewPath = '/dialogs/block/edit';
public function view()
{
$bv = new BlockView($this->block);
if (isset($_REQUEST['arGridMaximumColumns'])) {
$this->area->setAreaGridMaximumColumns(intval($_REQUEST['arGridMaximumColumns']));
}
if (isset($_REQUEST['arEnableGridContainer']) && $_REQUEST['arEnableGridContainer'] == 1) {
$this->area->enableGridContainer();
}
$bv->addScopeItems(array('c' => $this->page, 'a' => $this->area, 'dialogController' => $this));
$this->set('bv', $bv);
}
protected function validateBlock($b)
{
$bi = $b->getInstance();
if ($b->getBlockTypeHandle() == BLOCK_HANDLE_SCRAPBOOK_PROXY) {
$_b = Block::getByID($bi->getOriginalBlockID());
$bi = $_b->getInstance(); // for validation
}
$e = $bi->validate($_POST);
if ($e === true) {
$e = null;
}
return $e;
}
public function submit()
{
if ($this->validateAction() && $this->canAccess()) {
$app = Application::getFacadeApplication();
// validate the request
$e = $this->validateBlock($this->block);
if ($e instanceof ErrorList && $e->has()) {
$formatter = new JsonFormatter($e);
$response = $formatter->asArray();
return $app->make(ResponseFactoryInterface::class)->create(json_encode($response));
}
// create a new version of the block
$b = $this->getBlockToEdit();
$pr = $this->getEditResponse($b);
$b->update($_POST);
$event = new BlockEdit($b, $this->page);
Events::dispatch('on_block_edit', $event);
return $app->make(ResponseFactoryInterface::class)->json($pr);
}
}
protected function canAccess()
{
return $this->permissions->canEditBlock();
}
}