Advertisement
Guest User

Untitled

a guest
May 23rd, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. class TilePage extends Page {
  2.  
  3.     static $db = array(
  4.         "LayoutType" => "Enum('2->1,1->2,3', '2->1')"
  5.     );
  6.  
  7.     static $has_one = array(
  8.         "BackgroundImage" => "Image"
  9.     );
  10.  
  11.     static $has_many = array(
  12.         "Tiles" => "Tile",
  13.         "Tiles.ParentPage" => "Tile"
  14.     );
  15.  
  16.     public function getCMSFields() {
  17.         $fields = parent::getCMSFields();
  18.         $fields->removeByName("Content");
  19.         $fields->addFieldToTab("Root.Main", new UploadField("BackgroundImage", "Background Image"), "Metadata");
  20.         $fields->addFieldToTab("Root.Tiles", new DropdownField("LayoutType", "Layout Type (LeftSize -> RightSize)", singleton("TilePage")->dbObject("LayoutType")->enumValues()));
  21.         $fields->addFieldToTab("Root.Tiles", new GridField("Tiles", "Available Tiles", $this->Tiles(), GridFieldConfig_RecordEditor::create()));
  22.         return $fields;
  23.     }
  24. }
  25.  
  26.  
  27. class Tile extends DataObject {
  28.  
  29.     static $db = array(
  30.         "Name" => "Varchar",
  31.         "HorizontalSize" => "Int",
  32.         "VerticalSize" => "Int",
  33.         "Location" => "Enum('Left, Right', 'Left')",
  34.         "Visible" => "Boolean",
  35.         "Order" => "Int",
  36.         "LinkToURL" => "Varchar(255)"
  37.     );
  38.  
  39.     static $has_one = array(
  40.         "BackgroundImage" => "Image",
  41.         "ParentPage" => "Page",
  42.         "LinkToPage" => "Page"
  43.     );
  44.  
  45.     static $summary_fields = array(
  46.         "Name", "Location", "Visible", "Order"
  47.     );
  48.  
  49.     static $defaults = array(
  50.         "Visible" => true
  51.     ); 
  52.  
  53.     public function getCMSFields() {
  54.         return new FieldList(
  55.             new TextField("Name", "Name"),
  56.             new DropdownField("ClassName", "Tile Type", array(
  57.                 "BasicTile" => "Basic Tile",
  58.                 "Tile" => "Image Only Tile",
  59.                 "ImageRotaterTile" => "Image Rotater Tile",
  60.                 "TextRotaterTile" => "Text Rotater Tile"
  61.             )),
  62.             new CheckboxField("Visible", "Visible"),
  63.             new TextField("HorizontalSize", "Horizontal Tile Size (1, 2 or 3)", "", 1),
  64.             new TextField("VerticalSize", "Vertical Tile Size (1, 2 or 3)", "", 1),
  65.             new DropdownField("Location", "Location", singleton("Tile")->dbObject("Location")->enumValues()),
  66.             new UploadField("BackgroundImage", "Background Image"),
  67.             new TextField("Order", "Order (lower numbers will go first)"),
  68.             new TreeDropdownField("LinkToPage", "Link to Page", "SiteTree"),
  69.             new TextField("LinkToURL", "Link to URL (overrides Link to Page)")
  70.         );
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement