1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Admin; |
4
|
|
|
|
5
|
|
|
use Dynamic\Foxy\Model\Setting; |
6
|
|
|
use SilverStripe\Admin\LeftAndMain; |
7
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
|
|
|
8
|
|
|
use SilverStripe\Control\Director; |
9
|
|
|
use SilverStripe\Forms\Form; |
10
|
|
|
use SilverStripe\Forms\FormAction; |
11
|
|
|
use SilverStripe\Forms\HiddenField; |
12
|
|
|
use SilverStripe\Forms\LiteralField; |
13
|
|
|
use SilverStripe\ORM\ArrayList; |
14
|
|
|
use SilverStripe\ORM\DataObject; |
15
|
|
|
use SilverStripe\ORM\ValidationException; |
16
|
|
|
use SilverStripe\ORM\ValidationResult; |
17
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
|
|
|
18
|
|
|
use SilverStripe\Versioned\RecursivePublishable; |
19
|
|
|
use SilverStripe\View\ArrayData; |
20
|
|
|
use SilverStripe\View\Requirements; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class FoxyAdmin |
24
|
|
|
*/ |
25
|
|
|
class FoxyAdmin extends LeftAndMain |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private static $url_segment = 'foxystripe'; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private static $url_rule = '/$Action/$ID/$OtherID'; |
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var int |
39
|
|
|
*/ |
40
|
|
|
private static $menu_priority = 0; |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private static $menu_title = 'FoxyStripe'; |
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private static $menu_icon_class = 'font-icon-cog'; |
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private static $tree_class = Setting::class; |
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
private static $required_permission_codes = ['EDIT_GLOBAL_PERMISSION']; |
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Initialises the {@link TemplateConfigSetting} controller. |
64
|
|
|
*/ |
65
|
|
|
public function init() |
66
|
|
|
{ |
67
|
|
|
parent::init(); |
68
|
|
|
if (class_exists(SiteTree::class)) { |
69
|
|
|
Requirements::javascript('silverstripe/cms: client/dist/js/bundle.js'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param null $id |
|
|
|
|
75
|
|
|
* @param null $fields |
|
|
|
|
76
|
|
|
* |
77
|
|
|
* @return $this|Form |
78
|
|
|
*/ |
79
|
|
|
public function getEditForm($id = null, $fields = null) |
80
|
|
|
{ |
81
|
|
|
$config = Setting::current_foxy_setting(); |
82
|
|
|
$fields = $config->getCMSFields(); |
83
|
|
|
// Tell the CMS what URL the preview should show |
84
|
|
|
$home = Director::absoluteBaseURL(); |
85
|
|
|
$fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); |
86
|
|
|
// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load |
87
|
|
|
$fields->push($navField = new LiteralField( |
88
|
|
|
'SilverStripeNavigator', |
89
|
|
|
$this->getSilverStripeNavigator() |
90
|
|
|
)); |
91
|
|
|
$navField->setAllowHTML(true); |
92
|
|
|
// Retrieve validator, if one has been setup (e.g. via data extensions). |
93
|
|
|
if ($config->hasMethod('getCMSValidator')) { |
94
|
|
|
$validator = $config->getCMSValidator(); |
|
|
|
|
95
|
|
|
} else { |
96
|
|
|
$validator = null; |
97
|
|
|
} |
98
|
|
|
$actions = $config->getCMSActions(); |
99
|
|
|
$negotiator = $this->getResponseNegotiator(); |
100
|
|
|
$form = Form::create( |
101
|
|
|
$this, |
102
|
|
|
'EditForm', |
103
|
|
|
$fields, |
104
|
|
|
$actions, |
105
|
|
|
$validator |
106
|
|
|
)->setHTMLID('Form_EditForm'); |
107
|
|
|
$form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
|
|
|
|
108
|
|
|
$request = $this->getRequest(); |
109
|
|
|
if ($request->isAjax() && $negotiator) { |
110
|
|
|
$result = $form->forTemplate(); |
111
|
|
|
return $negotiator->respond($request, array( |
112
|
|
|
'CurrentForm' => function () use ($result) { |
113
|
|
|
return $result; |
114
|
|
|
}, |
115
|
|
|
)); |
116
|
|
|
} |
117
|
|
|
}); |
118
|
|
|
$form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); |
119
|
|
|
$form->setAttribute('data-pjax-fragment', 'CurrentForm'); |
120
|
|
|
if ($form->Fields()->hasTabSet()) { |
121
|
|
|
$form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
122
|
|
|
} |
123
|
|
|
$form->setHTMLID('Form_EditForm'); |
124
|
|
|
$form->loadDataFrom($config); |
125
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
126
|
|
|
// Use <button> to allow full jQuery UI styling |
127
|
|
|
$actions = $actions->dataFields(); |
128
|
|
|
if ($actions) { |
|
|
|
|
129
|
|
|
/** @var FormAction $action */ |
130
|
|
|
foreach ($actions as $action) { |
131
|
|
|
$action->setUseButtonTag(true); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
$this->extend('updateEditForm', $form); |
135
|
|
|
return $form; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Save the current sites {@link GlobalSiteSetting} into the database. |
140
|
|
|
* |
141
|
|
|
* @param array $data |
142
|
|
|
* @param Form $form |
143
|
|
|
* |
144
|
|
|
* @return string |
145
|
|
|
* @throws ValidationException |
146
|
|
|
*/ |
147
|
|
|
public function save_foxy_setting($data, $form) |
|
|
|
|
148
|
|
|
{ |
149
|
|
|
$data = $form->getData(); |
150
|
|
|
$siteConfig = DataObject::get_by_id(Setting::class, $data['ID']); |
151
|
|
|
$form->saveInto($siteConfig); |
152
|
|
|
$siteConfig->write(); |
153
|
|
|
if ($siteConfig->hasExtension(RecursivePublishable::class)) { |
154
|
|
|
$siteConfig->publishRecursive(); |
155
|
|
|
} |
156
|
|
|
$this->response->addHeader( |
157
|
|
|
'X-Status', |
158
|
|
|
rawurlencode(_t('SilverStripe\\Admin\\LeftAndMain.SAVEDUP', 'Saved.')) |
159
|
|
|
); |
160
|
|
|
return $form->forTemplate(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param bool $unlinked |
165
|
|
|
* |
166
|
|
|
* @return ArrayList |
167
|
|
|
*/ |
168
|
|
|
public function Breadcrumbs($unlinked = false) |
169
|
|
|
{ |
170
|
|
|
return new ArrayList(array( |
171
|
|
|
new ArrayData(array( |
172
|
|
|
'Title' => static::menu_title(), |
173
|
|
|
'Link' => $this->Link(), |
174
|
|
|
)), |
175
|
|
|
)); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths