/** * Create an uploadfield that can be used in a translation context. * Attaching, deleting, sorting will only be allowed in the master language. * If the page is translated, only allow editing of file title/content (eg. translate) * @param string $name the field name * @param $collection the file collection * @param string|null $title the field label (title) * @param string|null $sortField field to sort items on (in translation context). Set this * parameter to null if there's no sorting * @return UploadField instance or null */ public static function translatable_uploadfield($name, SS_List $collection, $title = null, $sortField = 'SortOrder') { $uploadField = null; // create two different upload fields, depending on locale if (Translatable::default_locale() == Translatable::get_current_locale()) { // for the master language, create a regular sortable upload field if (class_exists('SortableUploadField')) { $uploadField = SortableUploadField::create($name, $title, $collection); } else { $uploadField = UploadField::create($name, $title, $collection); } } else { // for all other languages, access the files in read-only if ($sortField) { $uploadField = UploadField::create('Translate.' . $name, $title, $collection->Sort($sortField)); } else { $uploadField = UploadField::create('Translate.' . $name, $title, $collection); } // prevent uploads $uploadField->setConfig('canUpload', false); // prevent attaching $uploadField->setConfig('canAttachExisting', false); // use a custom button-template with only a edit-button $uploadField->setTemplateFileButtons('UploadField_TranslationButtons'); } if ($uploadField) { $uploadField->setFileEditFields('getUploadEditorFields'); } return $uploadField; }
/** * CMS Fields * @return array */ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab("Root.Main", array(SortableUploadField::create('Images', 'Current Image(s)'))); $this->extend('updateCMSFields', $fields); return $fields; }
public function getCMSFields() { $fields = new FieldList([TextField::create('Title')]); if ($this->exists()) { $folderName = 'Documents'; $config = $this->Page()->exists() ? $this->Page()->config()->get('page_documents') : null; if (is_array($config)) { if (isset($config['folder'])) { $folderName = $config['folder']; } if (isset($config['section']) && $config['section']) { $filter = new URLSegmentFilter(); $section = implode('-', array_map(function ($string) { return ucfirst($string); }, explode('-', $filter->filter($this->Title)))); $folderName .= '/' . $section; } } $fields->push(SortableUploadField::create('Documents', 'Documents')->setDescription('Drag documents by thumbnail to sort')->setFolderName($folderName)); } else { $fields->push(LiteralField::create('DocumentsNotSaved', '<p>Save category to add documents</p>')); } $this->extend('updateCMSFields', $fields); return $fields; }
public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName('HideDescription'); $upload_folder = Controller::join_links("gallery", $this->ID); $sortable_field = SortableUploadField::create('Images', 'Images to associate with this page')->setFolderName($upload_folder); $fields->addFieldToTab("Root.Gallery", $sortable_field); return $fields; }
/** * CMS Fields * @return array */ public function getCMSFields() { $linksGridConfig = GridFieldConfig_RelationEditor::create(); if ($this->Links()->Count() > 0) { $linksGridConfig->addComponent(new GridFieldOrderableRows()); } $fields = parent::getCMSFields(); $fields->addFieldsToTab("Root.Main", array(TextareaField::create('Title')->setRows(1), HTMLEditorField::create('Content'), SortableUploadField::create('Images', 'Current Image(s)'), GridField::create('Links', 'Links', $this->Links(), $linksGridConfig))); return $fields; }
public function getCMSFields() { $fields = parent::getCMSFields(); $uploadField = null; if (class_exists('SortableUploadField')) { $uploadField = SortableUploadField::create('Images', _t('ImageBlock.IMAGES', 'Images')); } else { $uploadField = UploadField::create('Images', _t('ImageBlock.IMAGES', 'Images')); } $fields->addFieldToTab('Root.Main', $uploadField); $this->extend('updateCMSFields', $fields); return $fields; }
/** * @param FieldList $fields */ public function updateCMSFields(FieldList $fields) { //adding upload field - if item has already been saved //AssetsFolderID is set by the uploaddirrules module if ($this->owner->ID && $this->owner->AssetsFolderID != 0) { //this is the default, for non multi-language sites if (!class_exists('Translatable') || $this->owner->Locale == Translatable::default_locale()) { //The upload directory is expected to have been set in {@see UploadDirRules}, //This should be handled on the object that uses this extension! $imageField = SortableUploadField::create('Images', '')->setAllowedFileCategories('image'); $fields->addFieldToTab('Root.Images', $imageField); } else { //Note that images are administered in the original language $orig = $this->owner->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)); } } }
/** * Add CMS Fields for Gallery * * @var FieldList $fields */ public function updateCMSFields(FieldList $fields) { $fields->addFieldToTab('Root.Gallery', $GalleryImages = SortableUploadField::create('Images', 'Gallery Images')); $GalleryImages->setFolderName('gallery-images'); $GalleryImages->getValidator()->setAllowedExtensions('png', 'gif', 'jpeg', 'jpg'); }
public function getCMSFields() { // Get a list of available product classes $classnames = array_values(ClassInfo::subclassesFor("Product")); $product_types = array(); foreach ($classnames as $classname) { $instance = singleton($classname); $product_types[$classname] = $instance->i18n_singular_name(); } // If CMS Installed, use URLSegmentField, otherwise use text // field for URL if (class_exists('SiteTreeURLSegmentField')) { $baseLink = Controller::join_links(Director::absoluteBaseURL()); $url_field = SiteTreeURLSegmentField::create("URLSegment"); $url_field->setURLPrefix($baseLink); } else { $url_field = TextField::create("URLSegment"); } $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), $url_field, HTMLEditorField::create('Content', $this->fieldLabel('Content'))->setRows(20)->addExtraClass('stacked'), ToggleCompositeField::create('Metadata', _t('CatalogueAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4)), $tabSettings = new Tab('Settings', NumericField::create("BasePrice", _t("Catalogue.Price", "Price")), TextField::create("StockID", $this->fieldLabel('StockID'))->setRightTitle(_t("Catalogue.StockIDHelp", "For example, a product SKU")), DropdownField::create("TaxRateID", $this->fieldLabel('TaxRate'), TaxRate::get()->map())->setEmptyString(_t("Catalogue.None", "None")), TreeMultiSelectField::create("Categories", null, "CatalogueCategory"), DropdownField::create("ClassName", _t("CatalogueAdmin.ProductType", "Type of product"), $product_types)))); // Help text for MetaData on page content editor $metaFieldDesc->setRightTitle(_t('CatalogueAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help'); $metaFieldExtra->setRightTitle(_t('CatalogueAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />"))->addExtraClass('help'); if ($this->ID) { $fields->addFieldToTab('Root.Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images())); $fields->addFieldToTab('Root.Related', GridField::create('RelatedProducts', "", $this->RelatedProducts(), new GridFieldConfig_CatalogueRelated("Product", null, 'SortOrder'))); } $this->extend('updateCMSFields', $fields); return $fields; }
public function getCMSFields() { // Get a list of available product classes $classnames = ClassInfo::getValidSubClasses("CatalogueProduct"); $product_array = array(); foreach ($classnames as $classname) { if ($classname != "CatalogueProduct") { $description = Config::inst()->get($classname, 'description'); if ($classname == 'Product' && !$description) { $description = self::config()->description; } $description = $description ? $classname . ' - ' . $description : $classname; $product_array[$classname] = $description; } } // If we are creating a product, let us choose the product type if (!$this->ID) { $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', HiddenField::create("Title")->setValue(_t("Catalogue.NewProduct", "New Product")), ProductTypeField::create("ClassName", _t("Catalogue.SelectProductType", "Select a type of Product"), $product_array)))); } else { // If CMS Installed, use URLSegmentField, otherwise use text // field for URL if (class_exists('SiteTreeURLSegmentField')) { $baseLink = Controller::join_links(Director::absoluteBaseURL()); $url_field = SiteTreeURLSegmentField::create("URLSegment"); $url_field->setURLPrefix($baseLink); } else { $url_field = TextField::create("URLSegment"); } $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), $url_field, HTMLEditorField::create('Content', $this->fieldLabel('Content'))->setRows(20)->addExtraClass('stacked'), ToggleCompositeField::create('Metadata', _t('CatalogueAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4)), $tabSettings = new Tab('Settings', NumericField::create("BasePrice", _t("Catalogue.Price", "Price")), TextField::create("StockID", $this->fieldLabel('StockID'))->setRightTitle(_t("Catalogue.StockIDHelp", "For example, a product SKU")), DropdownField::create("TaxRateID", $this->fieldLabel('TaxRate'), TaxRate::get()->map())->setEmptyString(_t("Catalogue.None", "None")), TreeMultiSelectField::create("Categories", null, "CatalogueCategory"), CheckboxField::create("Disabled", _t("Catalogue.DisableProduct", "Disable this product (will not appear on shopfront)")), DropdownField::create("ClassName", _t("CatalogueAdmin.ProductType", "Type of product"), $product_array)), $tabImages = new Tab('Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images())))); // Help text for MetaData on page content editor $metaFieldDesc->setRightTitle(_t('CatalogueAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help'); $metaFieldExtra->setRightTitle(_t('CatalogueAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />"))->addExtraClass('help'); $fields->addFieldToTab('Root.Related', GridField::create('RelatedProducts', "", $this->RelatedProducts(), GridFieldConfig_RelationEditor::create())); } $this->extend('updateCMSFields', $fields); return $fields; }
public function getCMSFields() { $fields = parent::getCMSFields(); $field = SortableUploadField::create('Images', _t('CarouselPage.db_Images')); $field->setFolderName($this->getClassFolder()); // Enable HTML caption handling if captions are enabled if ($this->Captions) { $caption = CarouselCaptionField::create('Content', _t('CarouselPage.Caption')); $field->setFileEditFields(FieldList::create($caption)); unset($caption); } $root = $fields->fieldByName('Root'); $tab = $root->fieldByName('Images'); if (!$tab) { $tab = Tab::create('Images'); $tab->setTitle(_t('CarouselPage.db_Images')); $root->insertAfter($tab, 'Main'); } $tab->push($field); return $fields; }
/** * Add the "Images" tab to the content form of the page. * * The images are linked to the page with a many-many relationship, * so if an image is shared among different carousels there is no * need to upload it multiple times. * * @return FieldList */ public function getCMSFields() { $fields = parent::getCMSFields(); $field = SortableUploadField::create('Images', _t('CarouselPage.db_Images')); $field->setFolderName($this->getClassFolder()); $field->setFileEditFields('getCarouselEditFields'); $root = $fields->fieldByName('Root'); $tab = $root->fieldByName('Images'); if (!$tab) { $tab = Tab::create('Images'); $tab->setTitle(_t('CarouselPage.db_Images')); $root->insertAfter($tab, 'Main'); } $tab->push($field); return $fields; }
public function getCMSFields() { $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), TextField::create("URLSegment", $this->fieldLabel('URLSegment')), NumericField::create("Price", $this->fieldLabel('Price')), HTMLEditorField::create('Description', $this->fieldLabel('Price'))->setRows(20)->addExtraClass('stacked'), ToggleCompositeField::create('AdditionalData', 'Additional Data', array(NumericField::create("Quantity", $this->fieldLabel('Quantity')), TextField::create("SKU", $this->fieldLabel('SKU')), TextField::create("PackSize", $this->fieldLabel('PackSize')), TextField::create("Weight", $this->fieldLabel('Weight'))))->setHeadingLevel(4), ToggleCompositeField::create('Metadata', _t('CommerceAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4), CheckboxField::create("Disabled", $this->fieldLabel('Disabled'))), $tabImages = new Tab('Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images())))); // Help text for MetaData on page content editor $metaFieldDesc->setRightTitle(_t('CommerceAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help'); $metaFieldExtra->setRightTitle(_t('CommerceAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />"))->addExtraClass('help'); // Once product is saved, deal with more complex associations if ($this->ID) { // Deal with product features $add_button = new GridFieldAddNewInlineButton('toolbar-header-left'); $add_button->setTitle('Add Attribute'); $attributes_field = new GridField('Attributes', '', $this->Attributes(), GridFieldConfig::create()->addComponent(new GridFieldButtonRow('before'))->addComponent(new GridFieldToolbarHeader())->addComponent(new GridFieldTitleHeader())->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent($add_button)->addComponent(new GridFieldOrderableRows('Sort'))); $fields->addFieldToTab('Root.Attributes', $attributes_field); // Deal with customisations $add_button = new GridFieldAddNewButton('toolbar-header-left'); $add_button->setButtonName('Add Customisation'); $custom_config = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), $add_button, new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(20), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm(), new GridFieldOrderableRows('Sort')); $custom_field = GridField::create('Customisations', '', $this->Customisations(), $custom_config); $fields->addFieldToTab('Root.Customisations', $custom_field); $related_field = GridField::create('RelatedProducts', "", $this->RelatedProducts(), GridFieldConfig_RelationEditor::create()); $fields->addFieldToTab('Root.Related', $related_field); } $this->extend('updateCMSFields', $fields); return $fields; }