2011-07-06 08:39:34 +02:00
|
|
|
<?php
|
2012-05-18 06:33:34 +02:00
|
|
|
class CMSSettingsController extends LeftAndMain {
|
2011-07-06 08:39:34 +02:00
|
|
|
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $url_segment = 'settings';
|
|
|
|
private static $url_rule = '/$Action/$ID/$OtherID';
|
|
|
|
private static $menu_priority = -1;
|
|
|
|
private static $menu_title = 'Settings';
|
|
|
|
private static $tree_class = 'SiteConfig';
|
|
|
|
private static $required_permission_codes = array('EDIT_SITECONFIG');
|
2012-09-25 22:13:31 +02:00
|
|
|
|
2012-12-15 20:01:05 +01:00
|
|
|
public function init() {
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
Requirements::javascript(CMS_DIR . '/javascript/CMSMain.EditForm.js');
|
|
|
|
}
|
|
|
|
|
2012-07-13 11:00:21 +02:00
|
|
|
public function getResponseNegotiator() {
|
|
|
|
$neg = parent::getResponseNegotiator();
|
|
|
|
$controller = $this;
|
|
|
|
$neg->setCallback('CurrentForm', function() use(&$controller) {
|
|
|
|
return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
|
|
|
|
});
|
|
|
|
return $neg;
|
|
|
|
}
|
2011-07-06 08:39:34 +02:00
|
|
|
|
2012-03-08 18:19:38 +01:00
|
|
|
/**
|
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function getEditForm($id = null, $fields = null) {
|
2012-03-08 18:19:38 +01:00
|
|
|
$siteConfig = SiteConfig::current_site_config();
|
|
|
|
$fields = $siteConfig->getCMSFields();
|
|
|
|
|
2012-10-05 05:27:13 +02:00
|
|
|
// Tell the CMS what URL the preview should show
|
|
|
|
$fields->push(new HiddenField('PreviewURL', 'Preview URL', RootURLController::get_homepage_link()));
|
|
|
|
// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load
|
|
|
|
$fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()));
|
|
|
|
$navField->setAllowHTML(true);
|
|
|
|
|
2012-03-08 18:19:38 +01:00
|
|
|
$actions = $siteConfig->getCMSActions();
|
2013-05-10 15:00:57 +02:00
|
|
|
$form = CMSForm::create(
|
|
|
|
$this, 'EditForm', $fields, $actions
|
|
|
|
)->setHTMLID('Form_EditForm');
|
|
|
|
$form->setResponseNegotiator($this->getResponseNegotiator());
|
2013-08-24 12:33:38 +02:00
|
|
|
$form->addExtraClass('cms-content center cms-edit-form');
|
2012-07-13 11:00:21 +02:00
|
|
|
// don't add data-pjax-fragment=CurrentForm, its added in the content template instead
|
2012-05-18 06:33:34 +02:00
|
|
|
|
2012-03-08 18:19:38 +01:00
|
|
|
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
|
|
|
|
$form->setHTMLID('Form_EditForm');
|
|
|
|
$form->loadDataFrom($siteConfig);
|
|
|
|
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
|
|
|
|
|
|
|
|
// Use <button> to allow full jQuery UI styling
|
|
|
|
$actions = $actions->dataFields();
|
|
|
|
if($actions) foreach($actions as $action) $action->setUseButtonTag(true);
|
|
|
|
|
|
|
|
$this->extend('updateEditForm', $form);
|
|
|
|
|
|
|
|
return $form;
|
2011-07-06 08:39:34 +02:00
|
|
|
}
|
2012-03-09 23:35:43 +01:00
|
|
|
|
2012-10-05 05:27:13 +02:00
|
|
|
/**
|
|
|
|
* Used for preview controls, mainly links which switch between different states of the page.
|
|
|
|
*
|
|
|
|
* @return ArrayData
|
|
|
|
*/
|
|
|
|
public function getSilverStripeNavigator() {
|
|
|
|
return $this->renderWith('CMSSettingsController_SilverStripeNavigator');
|
|
|
|
}
|
2012-05-18 06:33:34 +02:00
|
|
|
|
2012-03-09 23:35:43 +01:00
|
|
|
/**
|
|
|
|
* Save the current sites {@link SiteConfig} into the database
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param Form $form
|
|
|
|
* @return String
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function save_siteconfig($data, $form) {
|
2012-03-09 23:35:43 +01:00
|
|
|
$siteConfig = SiteConfig::current_site_config();
|
|
|
|
$form->saveInto($siteConfig);
|
2013-11-30 14:12:19 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
$siteConfig->write();
|
|
|
|
} catch(ValidationException $ex) {
|
|
|
|
$form->sessionMessage($ex->getResult()->message(), 'bad');
|
|
|
|
return $this->getResponseNegotiator()->respond($this->request);
|
|
|
|
}
|
2012-03-09 23:35:43 +01:00
|
|
|
|
2012-05-18 06:54:33 +02:00
|
|
|
$this->response->addHeader('X-Status', rawurlencode(_t('LeftAndMain.SAVEDUP', 'Saved.')));
|
2012-07-13 11:00:21 +02:00
|
|
|
return $this->getResponseNegotiator()->respond($this->request);
|
2012-03-09 23:35:43 +01:00
|
|
|
}
|
2011-07-06 08:39:34 +02:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function LinkPreview() {
|
2012-10-05 05:27:13 +02:00
|
|
|
$record = $this->getRecord($this->currentPageID());
|
|
|
|
$baseLink = ($record && $record instanceof Page) ? $record->Link('?stage=Stage') : Director::absoluteBaseURL();
|
|
|
|
return $baseLink;
|
2011-10-29 19:13:19 +02:00
|
|
|
}
|
2012-03-02 20:45:44 +01:00
|
|
|
|
2012-09-19 12:07:46 +02:00
|
|
|
public function Breadcrumbs($unlinked = false) {
|
2012-07-18 13:51:30 +02:00
|
|
|
$defaultTitle = self::menu_title_for_class(get_class($this));
|
2012-03-02 20:45:44 +01:00
|
|
|
return new ArrayList(array(
|
|
|
|
new ArrayData(array(
|
2012-07-18 13:51:30 +02:00
|
|
|
'Title' => _t("{$this->class}.MENUTITLE", $defaultTitle),
|
2012-03-02 20:45:44 +01:00
|
|
|
'Link' => false
|
|
|
|
))
|
|
|
|
));
|
|
|
|
}
|
2011-10-29 19:13:19 +02:00
|
|
|
|
2012-03-27 06:05:11 +02:00
|
|
|
}
|