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
|
|
|
|
|
|
|
static $url_segment = 'settings';
|
|
|
|
static $url_rule = '/$Action/$ID/$OtherID';
|
|
|
|
static $menu_priority = -1;
|
|
|
|
static $menu_title = 'Settings';
|
2012-08-06 09:36:25 +02:00
|
|
|
static $tree_class = 'SiteConfig';
|
2012-09-25 22:13:31 +02:00
|
|
|
static $required_permission_codes = array('EDIT_SITECONFIG');
|
|
|
|
|
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();
|
|
|
|
$form = new Form($this, 'EditForm', $fields, $actions);
|
|
|
|
$form->addExtraClass('root-form');
|
2012-05-18 06:33:34 +02:00
|
|
|
$form->addExtraClass('cms-edit-form cms-panel-padded center');
|
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);
|
|
|
|
$siteConfig->write();
|
|
|
|
|
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
|
|
|
}
|