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