Source of file FoxyStripeAdmin.php
Size: 5,183 Bytes - Last Modified: 2021-12-24T06:45:37+00:00
/var/www/docs.ssmods.com/process/src/src/Admin/FoxyStripeAdmin.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 | <?php namespace Dynamic\FoxyStripe\Admin; use Dynamic\FoxyStripe\Model\FoxyStripeSetting; use SilverStripe\Admin\LeftAndMain; use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Control\Director; use SilverStripe\Forms\Form; use SilverStripe\Forms\FormAction; use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\LiteralField; use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ValidationException; use SilverStripe\ORM\ValidationResult; use SilverStripe\View\ArrayData; use SilverStripe\View\Requirements; class FoxyStripeAdmin extends LeftAndMain { /** * @var string */ private static $url_segment = 'foxystripe'; /** * @var string */ private static $url_rule = '/$Action/$ID/$OtherID'; /** * @var int */ private static $menu_priority = 4; /** * @var string */ private static $menu_title = 'FoxyStripe'; /** * @var string */ private static $menu_icon_class = 'font-icon-cog'; /** * @var string */ private static $tree_class = FoxyStripeSetting::class; /** * @var array */ private static $required_permission_codes = ['EDIT_GLOBAL_PERMISSION']; /** * Initialises the {@link FoxyStripeSetting} controller. */ public function init() { parent::init(); Requirements::javascript('silverstripe/cms: client/dist/js/bundle.js'); } /** * @param null $id * @param null $fields * * @return $this|Form */ public function getEditForm($id = null, $fields = null) { $config = FoxyStripeSetting::current_foxystripe_setting(); $fields = $config->getCMSFields(); // Tell the CMS what URL the preview should show $home = Director::absoluteBaseURL(); $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); // 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); // Retrieve validator, if one has been setup (e.g. via data extensions). if ($config->hasMethod('getCMSValidator')) { $validator = $config->getCMSValidator(); } else { $validator = null; } $actions = $config->getCMSActions(); $negotiator = $this->getResponseNegotiator(); $form = Form::create( $this, 'EditForm', $fields, $actions, $validator )->setHTMLID('Form_EditForm'); $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { $request = $this->getRequest(); if ($request->isAjax() && $negotiator) { $result = $form->forTemplate(); return $negotiator->respond($request, array( 'CurrentForm' => function () use ($result) { return $result; }, )); } return null; }); $form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); if ($form->Fields()->hasTabSet()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); } $form->setHTMLID('Form_EditForm'); $form->loadDataFrom($config); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Use <button> to allow full jQuery UI styling $actions = $actions->dataFields(); if ($actions) { /** @var FormAction $action */ foreach ($actions as $action) { $action->setUseButtonTag(true); } } $this->extend('updateEditForm', $form); return $form; } /** * Save the current sites {@link FoxyStripeSetting} into the database. * * @param $data * @param $form * * @return \SilverStripe\Control\HTTPResponse * @throws \SilverStripe\Control\HTTPResponse_Exception */ public function save_foxystripe_setting($data, $form) { $config = FoxyStripeSetting::current_foxystripe_setting(); $form->saveInto($config); try { $config->write(); } catch (ValidationException $ex) { $form->sessionMessage($ex->getResult()->message(), 'bad'); return $this->getResponseNegotiator()->respond($this->request); } $this->response->addHeader('X-Status', rawurlencode(_t('SilverStripe\\Admin\\LeftAndMain.SAVEDUP', 'Saved.'))); return $form->forTemplate(); } /** * @param bool $unlinked * * @return ArrayList */ public function Breadcrumbs($unlinked = false) { return new ArrayList(array( new ArrayData(array( 'Title' => static::menu_title(), 'Link' => $this->Link(), )), )); } } |