/
add.php
44 lines (36 loc) · 1.52 KB
/
add.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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Pages\Containers;
use Concrete\Core\Entity\Page\Container;
use Concrete\Core\Page\Container\Command\AddContainerCommand;
use Concrete\Core\Page\Container\Command\ContainerCommandValidator;
use Concrete\Core\Page\Controller\DashboardPageController;
class Add extends DashboardPageController
{
public function view()
{
$this->set('tokenMessage', 'add_container');
$this->render('/dashboard/pages/containers/form');
}
public function add_container()
{
if ($this->token->validate('add_container')) {
$container = new Container();
$container->setContainerName($this->request->request->get('containerName'));
$container->setContainerHandle($this->request->request->get('containerHandle'));
$container->setContainerIcon($this->request->request->get('containerIcon'));
$command = new AddContainerCommand($container);
$validator = $this->app->make(ContainerCommandValidator::class);
$errorList = $validator->validate($command);
if ($errorList->has()) {
$this->error->add($errorList);
} else {
$this->executeCommand($command);
$this->flash('success', t('Container added successfully.'));
return $this->buildRedirect('/dashboard/pages/containers');
}
} else {
$this->error->add($this->token->getErrorMessage());
}
$this->view();
}
}