Advertisement
Guest User

SS3 Image Widget

a guest
Aug 27th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2.  
  3. class ImageWidget extends Widget {
  4.    
  5.     static $db = array(
  6.       'ImageCaption' => 'Varchar(50)',
  7.       'LinkToPage' => 'Enum("No,Yes")'
  8.     );
  9.    
  10.     public static $has_one = array(
  11.       'WidgetImage' => 'Image',
  12.       'ImageLink' => 'SiteTree'
  13.     );  
  14.    
  15.     static $title = "";
  16.     static $cmsTitle = "Image";
  17.     static $description = "Add an image and optionally add a caption and link to a page on your website";
  18.      
  19.     public function getCMSFields() {
  20.       return new FieldList(                                            
  21.          DropdownField::create('WidgetImageID','Image (225px or wider)', Image::get()->map())
  22.             ->setEmptyString('--Select image--'),
  23.          new TextField('ImageCaption','Caption (optional)'),
  24.          new DropdownField('LinkToPage','Link to page?', singleton('ImageWidget')->dbObject('LinkToPage')->enumValues()),
  25.          DropdownField::create('ImageLinkID','Link to page (optional)', SiteTree::get()->map())
  26.             ->setEmptyString('--Select page--')
  27.       );
  28.     }
  29.  
  30. }
  31.  
  32. class ImageWidget_Controller extends Widget_Controller {      
  33.  
  34.       public function WidgetImageLink($pageID){
  35.          $page = SiteTree::get()->byID($pageID)->Link();
  36.          if ($page) return $page;
  37.       }
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement