function updateCMSFields(FieldList $fields) { //multiselect subtypes of orderitem if ($this->owner->isInDB() && $this->owner->ForItems) { $fields->addFieldToTab("Root.Main.Constraints.Products", ListBoxField::create("ProductTypes", "Product Types", $this->getTypes(false, $this->owner))->setMultiple(true)); } }
public function __construct($controller, $name) { $product = new Product(); $title = new TextField('Title', _t('Product.PAGETITLE', 'Product Title')); $urlSegment = new TextField('URLSegment', 'URL Segment'); $menuTitle = new TextField('MenuTitle', 'Navigation Title'); $sku = TextField::create('InternalItemID', _t('Product.CODE', 'Product Code/SKU'), '', 30); $categories = DropdownField::create('ParentID', _t("Product.CATEGORY", "Category"), $product->categoryoptions())->setDescription(_t("Product.CATEGORYDESCRIPTION", "This is the parent page or default category.")); $otherCategories = ListBoxField::create('ProductCategories', _t("Product.ADDITIONALCATEGORIES", "Additional Categories"), ProductCategory::get()->filter("ID:not", $product->getAncestors()->map('ID', 'ID'))->map('ID', 'NestedTitle')->toArray())->setMultiple(true); $model = TextField::create('Model', _t('Product.MODEL', 'Model'), '', 30); $featured = CheckboxField::create('Featured', _t('Product.FEATURED', 'Featured Product')); $allow_purchase = CheckboxField::create('AllowPurchase', _t('Product.ALLOWPURCHASE', 'Allow product to be purchased'), 1, 'Content'); $price = TextField::create('BasePrice', _t('Product.PRICE', 'Price'))->setDescription(_t('Product.PRICEDESC', "Base price to sell this product at."))->setMaxLength(12); $image = UploadField::create('Image', _t('Product.IMAGE', 'Product Image')); $content = new HtmlEditorField('Content', 'Content'); $fields = new FieldList(); $fields->add($title); //$fields->add($urlSegment); //$fields->add($menuTitle); //$fields->add($sku); $fields->add($categories); //$fields->add($otherCategories); $fields->add($model); $fields->add($featured); $fields->add($allow_purchase); $fields->add($price); $fields->add($image); $fields->add($content); //$fields = $product->getFrontEndFields(); $actions = new FieldList(new FormAction('submit', _t("ChefProductForm.ADDPRODUCT", 'Add product'))); $requiredFields = new RequiredFields(array('Title', 'Model', 'Price')); parent::__construct($controller, $name, $fields, $actions, $requiredFields); }
public function updateCMSFields(FieldList $fields) { $taxonomySourceFunction = function () { $source = TaxonomyTerm::get()->exclude('ParentID', 0); $result = array(); if ($source->count()) { foreach ($source as $term) { $result[$term->ID] = $term->getTaxonomyName() . ": {$term->Title}"; } } asort($result); return $result; }; $taxonomySource = $taxonomySourceFunction(); $fields->addFieldToTab('Root.Main', ListBoxField::create('Terms', 'Terms', $taxonomySource, null, null, true)->useAddNew('TaxonomyTerm', $taxonomySourceFunction, FieldList::create(TextField::create('Name', 'Title'), DropdownField::create('ParentID', 'Parent', TaxonomyTerm::get()->filter('ParentID', 0)->map()->toArray())->setEmptyString(''))), 'Content'); }
/** * Add product fields to CMS * @return FieldList updated field list */ public function getCMSFields() { self::disableCMSFieldsExtensions(); $fields = parent::getCMSFields(); $fields->fieldByName('Root.Main.Title')->setTitle(_t('Product.PAGETITLE', 'Product Title')); //general fields $fields->addFieldsToTab('Root.Main', array(TextField::create('InternalItemID', _t('Product.CODE', 'Product Code/SKU'), '', 30), DropdownField::create('ParentID', _t("Product.CATEGORY", "Category"), $this->categoryoptions())->setDescription(_t("Product.CATEGORYDESCRIPTION", "This is the parent page or default category.")), ListBoxField::create('ProductCategories', _t("Product.ADDITIONALCATEGORIES", "Additional Categories"), ProductCategory::get()->filter("ID:not", $this->getAncestors()->map('ID', 'ID'))->map('ID', 'NestedTitle')->toArray())->setMultiple(true), TextField::create('Model', _t('Product.MODEL', 'Model'), '', 30), CheckboxField::create('Featured', _t('Product.FEATURED', 'Featured Product')), CheckboxField::create('AllowPurchase', _t('Product.ALLOWPURCHASE', 'Allow product to be purchased'), 1)), 'Content'); //pricing $fields->addFieldsToTab('Root.Pricing', array(TextField::create('BasePrice', _t('Product.PRICE', 'Price'))->setDescription(_t('Product.PRICEDESC', "Base price to sell this product at."))->setMaxLength(12), TextField::create('CostPrice', _t('Product.COSTPRICE', 'Cost Price'))->setDescription(_t('Product.COSTPRICEDESC', 'Wholesale price before markup.'))->setMaxLength(12))); //physical measurements $fields->addFieldsToTab('Root.Shipping', array(TextField::create('Weight', sprintf(_t('Product.WEIGHT', 'Weight (%s)'), self::config()->weight_unit), '', 12), TextField::create('Height', sprintf(_t('Product.HEIGHT', 'Height (%s)'), self::config()->length_unit), '', 12), TextField::create('Width', sprintf(_t('Product.WIDTH', 'Width (%s)'), self::config()->length_unit), '', 12), TextField::create('Depth', sprintf(_t('Product.DEPTH', 'Depth (%s)'), self::config()->length_unit), '', 12))); if (!$fields->dataFieldByName('Image')) { $fields->addFieldToTab('Root.Images', UploadField::create('Image', _t('Product.IMAGE', 'Product Image'))); } self::enableCMSFieldsExtensions(); $this->extend('updateCMSFields', $fields); return $fields; }
/** * Block manager for Pages * */ public function updateCMSFields(FieldList $fields) { if ($fields->fieldByName('Root.Blocks') || in_array($this->owner->ClassName, $this->blockManager->getExcludeFromPageTypes()) || !$this->owner->exists()) { return; } if (!Permission::check('BLOCK_EDIT')) { return; } if (!$this->blockManager->getIncludeFromPageTypes() || in_array($this->owner->ClassName, $this->blockManager->getIncludeFromPageTypes())) { $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName); if ($areas && count($areas)) { $fields->addFieldToTab('Root.Blocks', LiteralField::create('PreviewLink', $this->areasPreviewButton())); // Blocks related directly to this Page $gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true)->addExisting($this->owner->class)->addComponent(new GridFieldOrderableRows()); // TODO it seems this sort is not being applied... $gridSource = $this->owner->Blocks(); // ->sort(array( // "FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '', // 'SiteTree_Blocks.Sort' => 'ASC', // 'Name' => 'ASC' // )); $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', 'Blocks', $gridSource, $gridConfig)); // Blocks inherited from BlockSets if ($this->blockManager->getUseBlockSets()) { $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true); if ($inheritedBlocks->count()) { $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false); if ($activeInherited->count()) { $fields->addFieldsToTab('Root.Blocks', array(GridField::create('InheritedBlockList', 'Blocks Inherited from Block Sets', $activeInherited, GridFieldConfig_BlockManager::create(false, false, false)), LiteralField::create('InheritedBlockListTip', "<p class='message'>Tip: Inherited blocks can be edited in the <a href='admin/block-admin'>Block Admin area</a><p>"))); } $fields->addFieldToTab('Root.Blocks', ListBoxField::create('DisabledBlocks', 'Disable Inherited Blocks', $inheritedBlocks->map('ID', 'Title'), null, null, true)->setDescription('Select any inherited blocks that you would not like displayed on this page.')); } else { $fields->addFieldToTab('Root.Blocks', ReadonlyField::create('DisabledBlocksReadOnly', 'Disable Inherited Blocks', 'This page has no inherited blocks to disable.')); } $fields->addFieldToTab('Root.Blocks', CheckboxField::create('InheritBlockSets', 'Inherit Blocks from Block Sets')); } } else { $fields->addFieldToTab('Root.Blocks', LiteralField::create('Blocks', 'This page type has no Block Areas configured.')); } } else { return; } }
/** * Add product fields to CMS * * @return FieldList updated field list */ public function getCMSFields() { self::disableCMSFieldsExtensions(); $fields = parent::getCMSFields(); $fields->fieldByName('Root.Main.Title')->setTitle(_t('Product.PageTitle', 'Product Title')); //general fields $fields->addFieldsToTab('Root.Main', array(TextField::create('InternalItemID', _t('Product.InternalItemID', 'Product Code/SKU'), '', 30), DropdownField::create('ParentID', _t("Product.Category", "Category"), $this->getCategoryOptions())->setDescription(_t("Product.CategoryDescription", "This is the parent page or default category.")), ListBoxField::create('ProductCategories', _t("Product.AdditionalCategories", "Additional Categories"), $this->getCategoryOptionsNoParent())->setMultiple(true), TextField::create('Model', _t('Product.Model', 'Model'), '', 30), CheckboxField::create('Featured', _t('Product.Featured', 'Featured Product')), CheckboxField::create('AllowPurchase', _t('Product.AllowPurchase', 'Allow product to be purchased'), 1)), 'Content'); //pricing $fields->addFieldsToTab('Root.Pricing', array(TextField::create('BasePrice', _t('Product.db_BasePrice', 'Price'))->setDescription(_t('Product.PriceDesc', "Base price to sell this product at."))->setMaxLength(12), TextField::create('CostPrice', _t('Product.db_CostPrice', 'Cost Price'))->setDescription(_t('Product.CostPriceDescription', 'Wholesale price before markup.'))->setMaxLength(12))); //physical measurements $fieldSubstitutes = array('LengthUnit' => self::config()->length_unit); $fields->addFieldsToTab('Root.Shipping', array(TextField::create('Weight', _t('Product.WeightWithUnit', 'Weight ({WeightUnit})', '', array('WeightUnit' => self::config()->weight_unit)), '', 12), TextField::create('Height', _t('Product.HeightWithUnit', 'Height ({LengthUnit})', '', $fieldSubstitutes), '', 12), TextField::create('Width', _t('Product.WidthWithUnit', 'Width ({LengthUnit})', '', $fieldSubstitutes), '', 12), TextField::create('Depth', _t('Product.DepthWithUnit', 'Depth ({LengthUnit})', '', $fieldSubstitutes), '', 12))); if (!$fields->dataFieldByName('Image')) { $fields->addFieldToTab('Root.Images', UploadField::create('Image', _t('Product.Image', 'Product Image'))); } self::enableCMSFieldsExtensions(); $this->extend('updateCMSFields', $fields); return $fields; }
/** * Block manager for Pages. * */ public function updateCMSFields(FieldList $fields) { if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) { return; } $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName); if ($areas && count($areas)) { $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks'))); if (BlockManager::config()->get('block_area_preview')) { $fields->addFieldToTab('Root.Blocks', LiteralField::create('PreviewLink', $this->areasPreviewButton())); } // Blocks related directly to this Page $gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true)->addExisting($this->owner->class)->addComponent(new GridFieldOrderableRows()); // TODO it seems this sort is not being applied... $gridSource = $this->owner->Blocks(); // ->sort(array( // "FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '', // 'SiteTree_Blocks.Sort' => 'ASC', // 'Name' => 'ASC' // )); $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig)); // Blocks inherited from BlockSets if ($this->blockManager->getUseBlockSets()) { $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true); if ($inheritedBlocks->count()) { $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false); if ($activeInherited->count()) { $fields->addFieldsToTab('Root.Blocks', array(GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited, GridFieldConfig_BlockManager::create(false, false, false)), LiteralField::create('InheritedBlockListTip', "<p class='message'>" . _t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', array('link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>')) . '<p>'))); } $fields->addFieldToTab('Root.Blocks', ListBoxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), $inheritedBlocks->map('ID', 'Title'), null, null, true)->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.'))); } else { $fields->addFieldToTab('Root.Blocks', ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable', 'This page has no inherited blocks to disable.'))); } $fields->addFieldToTab('Root.Blocks', CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets'))); } } }
/** * * @param FieldList $fields * @return void */ public function updateCMSFields(FieldList $fields) { $controller = Controller::curr(); if ($controller instanceof SecuredAssetAdmin || $controller instanceof CMSSecuredFileAddController) { Requirements::combine_files('securedassetsadmincmsfields.js', array(SECURED_FILES_MODULE_DIR . '/thirdparty/javascript/jquery-ui/timepicker/jquery-ui-sliderAccess.js', SECURED_FILES_MODULE_DIR . '/thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.min.js', SECURED_FILES_MODULE_DIR . "/javascript/SecuredFilesLeftAndMain.js")); Requirements::css(SECURED_FILES_MODULE_DIR . '/thirdparty/javascript/jquery-ui/timepicker/jquery-ui-timepicker-addon.min.css'); Requirements::css(SECURED_FILES_MODULE_DIR . "/css/SecuredFilesLeftAndMain.css"); Requirements::javascript(SECURED_FILES_MODULE_DIR . "/javascript/SecuredFilesLeftAndMain.js"); if ($this->isFile()) { $buttonsSecurity = $this->showButtonsSecurity(); $buttonsEmbargoExpiry = $this->showButtonsEmbargoExpiry(); // Embargo field $embargoTypeField = new OptionSetField("EmbargoType", "", array("None" => _t('AdvancedSecuredFiles.NONENICE', "None"), "Indefinitely" => _t('AdvancedSecuredFiles.INDEFINITELYNICE', "Hide document indefinitely"), "UntilAFixedDate" => _t('AdvancedSecuredFiles.UNTILAFIXEDDATENICE', 'Hide until set date'))); $embargoUntilDateField = DatetimeField::create('EmbargoedUntilDate', ''); $embargoUntilDateField->getDateField()->setConfig('showcalendar', true)->setConfig('dateformat', 'dd-MM-yyyy')->setConfig('datavalueformat', 'dd-MM-yyyy')->setAttribute('readonly', true); $embargoUntilDateField->getTimeField()->setAttribute('readonly', true); // Expiry field $expireTypeField = new OptionSetField("ExpiryType", "", array("None" => _t('AdvancedSecuredFiles.NONENICE', "None"), "AtAFixedDate" => _t('AdvancedSecuredFiles.ATAFIXEDDATENICE', 'Set file to expire on'))); $expiryDatetime = DatetimeField::create('ExpireAtDate', ''); $expiryDatetime->getDateField()->setConfig('showcalendar', true)->setConfig('dateformat', 'dd-MM-yyyy')->setConfig('datavalueformat', 'dd-MM-yyyy')->setAttribute('readonly', true); $expiryDatetime->getTimeField()->setAttribute('readonly', true); $securitySettingsGroup = FieldGroup::create(FieldGroup::create($embargoTypeField, $embargoUntilDateField)->addExtraClass('embargo option-change-datetime')->setName("EmbargoGroupField"), FieldGroup::create($expireTypeField, $expiryDatetime)->addExtraClass('expiry option-change-datetime')->setName("ExpiryGroupField")); } else { $buttonsSecurity = $this->showButtonsSecurity(); $buttonsEmbargoExpiry = ''; $securitySettingsGroup = FieldGroup::create(); } $canViewTypeField = new OptionSetField("CanViewType", "", array("Inherit" => _t('AdvancedSecuredFiles.INHERIT', "Inherit from parent folder"), "Anyone" => _t('SiteTree.ACCESSANYONE', 'Anyone'), "LoggedInUsers" => _t('SiteTree.ACCESSLOGGEDIN', 'Logged-in users'), "OnlyTheseUsers" => _t('SiteTree.ACCESSONLYTHESE', 'Only these people (choose from list)'))); $canEditTypeField = new OptionSetField("CanEditType", "", array("Inherit" => _t('AdvancedSecuredFiles.INHERIT', "Inherit from parent folder"), "LoggedInUsers" => _t('SiteTree.ACCESSLOGGEDIN', 'Logged-in users'), "OnlyTheseUsers" => _t('SiteTree.ACCESSONLYTHESE', 'Only these people (choose from list)'))); $groupsMap = array(); foreach (Group::get() as $group) { // Listboxfield values are escaped, use ASCII char instead of » $groupsMap[$group->ID] = $group->getBreadcrumbs(' > '); } asort($groupsMap); $viewerGroupsField = ListboxField::create("ViewerGroups", _t('AdvancedSecuredFiles.VIEWERGROUPS', "Viewer Groups"))->setMultiple(true)->setSource($groupsMap)->setAttribute('data-placeholder', _t('AdvancedSecuredFiles.GroupPlaceholder', 'Click to select group')); $editorGroupsField = ListBoxField::create("EditorGroups", _t('AdvancedSecuredFiles.EDITORGROUPS', "Editor Groups"))->setMultiple(true)->setSource($groupsMap)->setAttribute('data-placeholder', _t('AdvancedSecuredFiles.GroupPlaceholder', 'Click to select group')); $securitySettingsGroup->push(FieldGroup::create($canViewTypeField, $viewerGroupsField)->addExtraClass('whocanview option-change-listbox')->setName("CanViewGroupField")); $securitySettingsGroup->push(FieldGroup::create($canEditTypeField, $editorGroupsField)->addExtraClass('whocanedit option-change-listbox')->setName("CanEditGroupField")); $securitySettingsGroup->setName("SecuritySettingsGroupField")->addExtraClass('security-settings'); $showAdvanced = AdvancedAssetsFilesSiteConfig::is_security_enabled() || $this->isFile() && AdvancedAssetsFilesSiteConfig::is_embargoexpiry_enabled(); if ($showAdvanced) { $fields->insertAfter(LiteralField::create('BottomTaskSelection', $this->owner->renderWith('componentField', ArrayData::create(array('ComponentSecurity' => AdvancedAssetsFilesSiteConfig::component_cms_icon('security'), 'ComponentEmbargoExpiry' => AdvancedAssetsFilesSiteConfig::component_cms_icon('embargoexpiry'), 'ButtonsSecurity' => $buttonsSecurity, 'ButtonsEmbargoExpiry' => $buttonsEmbargoExpiry)))), "ParentID"); $fields->insertAfter($securitySettingsGroup, "BottomTaskSelection"); } } if (!is_a($this->owner, "Folder") && is_a($this->owner, "File")) { $parentIDField = $fields->dataFieldByName("ParentID"); if ($controller instanceof SecuredAssetAdmin) { $securedRoot = FileSecured::getSecuredRoot(); $parentIDField->setTreeBaseID($securedRoot->ID); $parentIDField->setFilterFunction(create_function('$node', "return \$node->Secured == 1;")); } else { $parentIDField->setFilterFunction(create_function('$node', "return \$node->Secured == 0;")); } // SilverStripe core has a bug for search function now, so disable it for now. $parentIDField->setShowSearch(false); } }