/**
* Additional magic happens here. Trick LeftAndMain into thinking we're a previewable SiteTree object.
*
* @return Form
*/
public function ItemEditForm()
{
Requirements::javascript(MODULATOR_PATH . '/javascript/LeftAndMain.Preview.js');
$form = parent::ItemEditForm();
$record = $this->getRecord();
// Hide the 'Save & publish' button if we're on a brand new module.
if ($record && $record->ID == 0) {
$actions = $form->Actions();
// Remove the publish button on the pre-module state
$actions->removeByName('action_publish');
// Remove the save action if there are no sub-classes to instantiate
$classes = ClassInfo::subclassesFor('PageModule');
unset($classes['PageModule']);
if (!count($classes)) {
$actions->removeByName('action_save');
}
}
// Enable CMS preview
// .cms-previewable enables the preview panel in the front-end
// .cms-pagemodule CSS class is used by our javascript to handle previews
if ($form && is_object($form)) {
$form->addExtraClass('cms-previewable cms-pagemodule');
}
// Creat a navigaor and point it at the parent page
$navigator = new SilverStripeNavigator($this->record->Page());
$navField = new LiteralField('SilverStripeNavigator', $navigator->renderWith('LeftAndMain_SilverStripeNavigator'));
$navField->setAllowHTML(true);
$fields = $form->Fields();
$fields->push($navField);
return $form;
}
/**
* @return Form
*/
public function getEditForm($id = null, $fields = null)
{
$siteConfig = SiteConfig::current_site_config();
$fields = $siteConfig->getCMSFields();
// 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);
$actions = $siteConfig->getCMSActions();
$form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm');
$form->setResponseNegotiator($this->getResponseNegotiator());
$form->addExtraClass('cms-content center cms-edit-form');
// don't add data-pjax-fragment=CurrentForm, its added in the content template instead
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;
}
/**
* @return Comosite FieldSet with Categorys and Items
*/
function getCompositeField()
{
//create new composite field group for each category
$oCatFieldSet = new CompositeField();
// Set the field group ID
$oCatFieldSet->setID('Cat' . $this->ID);
$oCatFieldSet->addExtraClass('category');
//create new composite field group for each category
$oCatField = new TextField($this->ID . '_' . $this->FieldName, $this->Title, null, null);
$oCatField->addExtraClass('category-field');
//Add Category Percentage Field to the Form
$oCatFieldSet->push($oCatField);
if ($this->Description) {
$oCatDescField = new LiteralField($this->ID . '_Description', '<p class="category-field-desc">' . $this->Description . '</p>');
$oCatDescField->addExtraClass('category-field');
$oCatFieldSet->push($oCatDescField);
}
//Add item Composite Field to this Composite Field
//now get all of the items matched with this category
$oFormCategoryItems = self::FormCategoryItems();
foreach ($oFormCategoryItems as $item) {
$oCatFieldSet->push($item->getFormField());
}
return $oCatFieldSet;
}
private function injectNavigatorAndPreview(&$form, &$fields)
{
$editForm = $fields->fieldByName('EditForm');
//TODO: Do we need to verify we are in the right controller?
$template = Controller::curr()->getTemplatesWithSuffix('_SilverStripeNavigator');
$navigator = new SilverStripeNavigator($this->owner->record);
$field = new LiteralField('SilverStripeNavigator', $navigator->renderWith($template));
$field->setAllowHTML(true);
$fields->push($field);
$form->addExtraClass('cms-previewable');
$form->addExtraClass(' cms-previewabledataobject');
$form->removeExtraClass('cms-panel-padded center');
}
public function ItemEditForm()
{
$form = parent::ItemEditForm();
// Do these action update only when the current record is_a newsletter
if ($this->record && $this->record instanceof Newsletter) {
$form->setActions($this->updateCMSActions($form->Actions()));
$form->Fields()->push(new HiddenField("PreviewURL", "PreviewURL", $this->LinkPreview()));
// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load
$navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator());
$navField->setAllowHTML(true);
$form->Fields()->push($navField);
}
return $form;
}
public function updateDynamicListCMSFields($fields)
{
// Make sure the draft records are being looked at.
$stage = Versioned::current_stage();
Versioned::reading_stage('Stage');
$used = EditableFormField::get()->filter(array('ClassName:PartialMatch' => 'DynamicList'));
// Determine whether this dynamic list is being used anywhere.
$found = array();
foreach ($used as $field) {
// This information is stored using a serialised list, therefore we need to iterate through.
if ($field->getSetting('ListTitle') === $this->owner->Title) {
// Make sure there are no duplicates recorded.
if (!isset($found[$field->ParentID]) && ($form = UserDefinedForm::get()->byID($field->ParentID))) {
$found[$field->ParentID] = "<a href='{$form->CMSEditLink()}'>{$form->Title}</a>";
}
}
}
// Display whether there were any dynamic lists found on user defined forms.
if (count($found)) {
$fields->removeByName('UsedOnHeader');
$fields->addFieldToTab('Root.Main', HeaderField::create('UsedOnHeader', 'Used On', 5));
}
$display = count($found) ? implode('<br>', $found) : 'This dynamic list is <strong>not</strong> used.';
$fields->removeByName('UsedOn');
$fields->addFieldToTab('Root.Main', LiteralField::create('UsedOn', '<div>' . $display . '</div>'));
Versioned::reading_stage($stage);
}
public function getCMSFields($params = null)
{
//fields that shouldn't be changed once coupon is used
$fields = new FieldList(array($tabset = new TabSet("Root", $maintab = new Tab("Main", TextField::create("Title"), CheckboxField::create("Active", "Active")->setDescription("Enable/disable all use of this discount."), HeaderField::create("ActionTitle", "Action", 3), $typefield = SelectionGroup::create("Type", array(new SelectionGroup_Item("Percent", $percentgroup = FieldGroup::create($percentfield = NumericField::create("Percent", "Percentage", "0.00")->setDescription("e.g. 0.05 = 5%, 0.5 = 50%, and 5 = 500%"), $maxamountfield = CurrencyField::create("MaxAmount", _t("MaxAmount", "Maximum Amount"))->setDescription("The total allowable discount. 0 means unlimited.")), "Discount by percentage"), new SelectionGroup_Item("Amount", $amountfield = CurrencyField::create("Amount", "Amount", "\$0.00"), "Discount by fixed amount")))->setTitle("Type"), OptionSetField::create("For", "Applies to", array("Order" => "Entire Order", "Cart" => "Cart Subtotal", "Shipping" => "Shipping Subtotal", "Items" => "Each Individual Item")), new Tab("Main", HeaderField::create("ConstraintsTitle", "Constraints", 3), LabelField::create("ConstraintsDescription", "Configure the requirements an order must meet for this discount to be valid:")), new TabSet("Constraints")))));
if (!$this->isInDB()) {
$fields->addFieldToTab("Root.Main", LiteralField::create("SaveNote", "<p class=\"message good\">More constraints will show up after you save for the first time.</p>"), "Constraints");
}
$this->extend("updateCMSFields", $fields, $params);
if ($count = $this->getUseCount()) {
$fields->addFieldsToTab("Root.Usage", array(HeaderField::create("UseCount", sprintf("This discount has been used {$count} time%s.", $count > 1 ? "s" : "")), HeaderField::create("TotalSavings", sprintf("A total of %s has been saved by customers using this discount.", $this->SavingsTotal), "3"), GridField::create("Orders", "Orders", $this->getAppliedOrders(), GridFieldConfig_RecordViewer::create()->removeComponentsByType("GridFieldViewButton"))));
}
if ($params && isset($params['forcetype'])) {
$valuefield = $params['forcetype'] == "Percent" ? $percentfield : $amountfield;
$fields->insertAfter($valuefield, "Type");
$fields->removeByName("Type");
} elseif ($this->Type && (double) $this->{$this->Type}) {
$valuefield = $this->Type == "Percent" ? $percentfield : $amountfield;
$fields->removeByName("Type");
$fields->insertAfter($valuefield, "ActionTitle");
$fields->replaceField($this->Type, $valuefield->performReadonlyTransformation());
if ($this->Type == "Percent") {
$fields->insertAfter($maxamountfield, "Percent");
}
}
return $fields;
}
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root', 'Pages');
$fields->removeFieldsFromTab('Root.Main', array('SortOrder', 'showBlockbyClass', 'shownInClass', 'MemberVisibility'));
$fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title');
$memberGroups = Group::get();
$sourcemap = $memberGroups->map('Code', 'Title');
$source = array('anonymous' => 'Anonymous visitors');
foreach ($sourcemap as $mapping => $key) {
$source[$mapping] = $key;
}
$memberVisibility = new CheckboxSetField($name = "MemberVisibility", $title = "Show block for specific groups", $source);
$memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.');
$availabelClasses = $this->availableClasses();
$inClass = new CheckboxSetField($name = "shownInClass", $title = "Show block for specific content types", $availabelClasses);
$filterSelector = OptionsetField::create('showBlockbyClass', 'Choose filter set', array('0' => 'by page', '1' => 'by page/data type'))->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>');
$availablePages = Page::get()->exclude('ClassName', array('ErrorPage', 'RedirectorPage', 'VirtualPage'));
$pageSelector = new CheckboxSetField($name = "Pages", $title = "Show on Page(s)", $availablePages->map('ID', 'Title'));
if ($this->canConfigPageAndType(Member::currentUser())) {
$fields->addFieldsToTab('Root.VisibilitySettings', array($filterSelector, $pageSelector, $inClass));
}
if ($this->canConfigMemberVisibility(Member::currentUser())) {
$fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility);
}
if (!$fields->fieldByName('Options')) {
$fields->insertBefore($right = RightSidebar::create('Options'), 'Root');
}
$fields->addFieldsToTab('Options', array(CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'), CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper')));
return $fields;
}
public function getCMSFields()
{
$fields = parent::getCMSFields();
//adding upload field - if item has already been saved
if ($this->ID && $this->AssetsFolderID != 0) {
//this is the default, for non multi-language sites
if (!class_exists('Translatable') || $this->Locale == Translatable::default_locale()) {
//Use SortableUploadField instead of UploadField!
//The upload directory is expected to have been set in {@see UploadDirRules},
//and should be something like: "assets/ID-Pagename"
//TODO: This could easily be configurable through yml files (to e.g. "assets/galleries/ID"),
//so this module could do without the upload dir rules
//
//read more about adding additinoal metadata to images here:
//http://doc.silverstripe.org/framework/en/reference/uploadfield
$imageField = new SortableUploadField('Images', '');
$fields->addFieldToTab('Root.Images', $imageField);
} else {
$orig = $this->getTranslation(Translatable::default_locale());
$html = sprintf('<a href="%s">%s</a>', Controller::join_links($orig->CMSEditLink(), '?locale=' . $orig->Locale), 'Images are administered through ' . i18n::get_locale_name($orig->Locale));
$fields->addFieldToTab('Root.Images', LiteralField::create('ImagesDesc', $html));
}
}
return $fields;
}
/**
* Gets a list of form fields for editing the record.
* These records should never be edited, so a readonly list of fields
* is forced.
*
* @return FieldList
*/
public function getCMSFields()
{
preg_match("/<body[^>]*>(.*?)<\\/body>/is", $this->Body, $matches);
$contents = $matches ? $matches[1] : "";
$f = FieldList::create(ReadonlyField::create('To'), ReadonlyField::create('Subject'), ReadonlyField::create('BCC'), ReadonlyField::create('CC'), HeaderField::create('Email contents', 5), LiteralField::create('BodyContents', "<div class='field'>{$contents}</div>"));
return $f;
}
public function updateCMSFields(FieldList $fields)
{
$fields->removeByName(array('Lat', 'Lng'));
// Adds Lat/Lng fields for viewing in the CMS
$compositeField = CompositeField::create();
$compositeField->push($overrideField = CheckboxField::create('LatLngOverride', 'Override Latitude and Longitude?'));
$overrideField->setDescription('Check this box and save to be able to edit the latitude and longitude manually.');
if ($this->owner->Lng && $this->owner->Lat) {
$googleMapURL = 'http://maps.google.com/?q=' . $this->owner->Lat . ',' . $this->owner->Lng;
$googleMapDiv = '<div class="field"><label class="left" for="Form_EditForm_MapURL_Readonly">Google Map</label><div class="middleColumn"><a href="' . $googleMapURL . '" target="_blank">' . $googleMapURL . '</a></div></div>';
$compositeField->push(LiteralField::create('MapURL_Readonly', $googleMapDiv));
}
if ($this->owner->LatLngOverride) {
$compositeField->push(TextField::create('Lat', 'Lat'));
$compositeField->push(TextField::create('Lng', 'Lng'));
} else {
$compositeField->push(ReadonlyField::create('Lat_Readonly', 'Lat', $this->owner->Lat));
$compositeField->push(ReadonlyField::create('Lng_Readonly', 'Lng', $this->owner->Lng));
}
if ($this->owner->hasExtension('Addressable')) {
// If using addressable, put the fields with it
$fields->addFieldToTab('Root.Address', ToggleCompositeField::create('Coordinates', 'Coordinates', $compositeField));
} else {
if ($this->owner instanceof SiteTree) {
// If SIteTree but not using Addressable, put after 'Metadata' toggle composite field
$fields->insertAfter($compositeField, 'ExtraMeta');
} else {
$fields->addFieldToTab('Root.Main', ToggleCompositeField::create('Coordinates', 'Coordinates', $compositeField));
}
}
}
请发表评论