Source of file SideTextWidget.php
Size: 3,585 Bytes - Last Modified: 2021-12-23T10:47:42+00:00
/var/www/docs.ssmods.com/process/src/SideTextWidget.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | <?php class SideTextWidget extends Widget { public static $has_one = array( "Content" => "SideTextWidget_DataObject" ); public static $title = "Side bar section"; public static $cmsTitle = "Side bar section"; public static $description = "Add a section to your side bar"; public function MyContent() { return DataObject::get_by_id("SideTextWidget_DataObject", $this->ContentID); } public function getCMSFields() { $source = DataObject::get("SideTextWidget_DataObject"); if ($source) { $list = $source->toDropdownMap("ID", "Title", "--- SELECT SIDE TEXT WIDGET ---"); $listField = new DropdownField("ContentID", "Side Text Widget <a href=\"/admin/sidetextwidget/\" target=\"_blank\">edit options here</a>", $list); } else { $listField = new DropdownField("ContentID", "Side Text Widget <a href=\"/admin/sidetextwidget/\" target=\"_blank\">edit options here</a>", array()); } return new FieldSet( $listField ); } } class SideTextWidget_DataObject extends DataObject { public static $db = array( "Title" => "Varchar(256)", "Body" => "HTMLText", "Caption" => "Varchar" ); public static $has_one = array( "Image" => "Image", "ImageLink" => "SiteTree" ); public static $summary_fields = array("Title" => "Title"); //note no => for relational fields public static $singular_name = "Sidebar Section"; public static $plural_name = "Sidebar Sections"; //defaults public static $default_sort = "Title"; public function SideText() { if (strcmp($this->Title(), "") == 0 && strcmp($this->Text(), "") == 0) { return false; } else { return true; } } public function getCMSFields() { HtmlEditorConfig::get('sidetextwidget')->setOption('priority', 2); HtmlEditorConfig::set_active("sidetextwidget"); $fields = parent::getCMSFields(); $fields->removeByName("Caption"); $fields->removeByName("ImageLinkID"); $fields->removeByName("Image"); $fields->addFieldsToTab( "Root.Main", new TextField("Title", "Title") ); $fields->addFieldToTab("Root.Images", new TreeDropdownField("ImageLinkID", "Image Link", "SiteTree")); $fields->addFieldToTab("Root.Images", new TextField("Caption", "Image Caption")); $fields->addFieldToTab("Root.Images", new ImageField("Image", "Image (width will be set to 100pixels)")); $fields->addFieldToTab("Root.Main", new HTMLEditorField("Body", "Text", 2, 2)); return $fields; } } class SideTextWidget_ModelAdmin extends ModelAdmin { public static $managed_models = array("SideTextWidget_DataObject"); public static $url_segment = 'sidetextwidget'; public static $menu_title = 'Side Text Widgets'; public $showImportForm = false; public function init() { parent::init(); } } class SideTextWidget_CMSHack extends LeftAndMainDecorator { public function init() { HtmlEditorConfig::get('cms')->setOption('theme_advanced_blockformats', 'p,h1'); HtmlEditorConfig::get('cms')->setButtonsForLine(1, 'undo, redo, separator, cut, copy, pastetext, separator, ssimage, sslink, unlink, separator, fullscreen, advcode, formatselect'); HtmlEditorConfig::get('cms')->setButtonsForLine(2); HtmlEditorConfig::get('cms')->setButtonsForLine(3); } } |