-
Notifications
You must be signed in to change notification settings - Fork 453
/
attributes.php
145 lines (122 loc) · 4.1 KB
/
attributes.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
namespace Concrete\Controller\Dialog\SiteType;
use Concrete\Controller\Backend\UserInterface as BackendInterfaceController;
use Concrete\Core\Application\EditResponse;
use Concrete\Core\Attribute\Category\CategoryInterface;
use Concrete\Core\Attribute\Category\CategoryService;
use Concrete\Core\Attribute\Key\Component\KeySelector\ControllerTrait as KeySelectorControllerTrait;
use Concrete\Core\Entity\Site\Skeleton;
use Concrete\Core\Entity\Site\Type as SiteType;
use Concrete\Core\Error\ErrorList\ErrorList;
use Concrete\Core\Error\UserMessageException;
use Concrete\Core\Filesystem\ElementManager;
use Concrete\Core\Page\Page;
use Concrete\Core\Permission\Checker;
use Concrete\Core\Site\Type\Skeleton\Service as SkeletonService;
use Symfony\Component\HttpFoundation\JsonResponse;
class Attributes extends BackendInterfaceController
{
use KeySelectorControllerTrait;
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Controller\Controller::$viewPath
*/
protected $viewPath = '/dialogs/site_type/attributes';
/**
* @var CategoryInterface
*/
protected $category;
/**
* @var SiteType|null
*/
protected $requestSiteType;
/**
* @var Skeleton
*/
private $skeleton;
public function __construct(CategoryService $attributeCategoryService)
{
parent::__construct();
$categoryEntity = $attributeCategoryService->getByHandle('site_type');
$this->category = $categoryEntity->getAttributeKeyCategory();
}
/**
* {@inheritdoc}
*
* @see \Concrete\Controller\Backend\UserInterface::canAccess()
*/
public function canAccess()
{
$p = Page::getByPath('/dashboard/system/multisite/types');
$permissions = new Checker($p);
$skeleton = $this->getTypeSkeleton();
return $skeleton !== null && $permissions->canViewPage();
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Attribute\Key\Component\KeySelector\ControllerTrait::getObjects()
*/
public function getObjects(): array
{
return [$this->getTypeSkeleton()];
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Attribute\Key\Component\KeySelector\ControllerTrait::getCategory()
*/
public function getCategory(): CategoryInterface
{
return $this->category;
}
public function canEditAttributeKey(int $akID): bool
{
return true;
}
public function view($stID)
{
$keySelector = $this->app->make(ElementManager::class)->get('attribute/component/key_selector', [
'category' => $this->getCategory()
]);
$controller = $keySelector->getElementController();
$controller->setSelectAttributeUrl($this->action('get_attribute'));
$controller->setObjects($this->getObjects());
$this->set('keySelector', $keySelector);
}
public function submit()
{
if ($this->validateAction()) {
$attributesResponse = $this->saveAttributes();
$message = new EditResponse();
if ($attributesResponse instanceof ErrorList) {
$message->setError($attributesResponse);
} else {
$message->setMessage(t('Attributes updated successfully.'));
}
return new JsonResponse($message);
}
}
protected function getTypeSkeleton(): Skeleton
{
if (!$this->skeleton) {
$skeletonService = $this->app->make(SkeletonService::class);
$siteType = $this->getSiteTypeFromRequest();
$this->skeleton = $skeletonService->getSkeleton($siteType);
}
return $this->skeleton;
}
protected function getSiteTypeFromRequest()
{
if (!isset($this->requestSiteType)) {
if ($this->request->attributes->has('stID')) {
$this->requestSiteType = $this->app['site/type']->getByID($this->request->attributes->get('stID'));
}
}
if (!$this->requestSiteType) {
throw new UserMessageException(t('Invalid site type id.'));
}
return $this->requestSiteType;
}
}