Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ImageWidget extends Widget {
- static $db = array(
- 'ImageCaption' => 'Varchar(50)',
- 'LinkToPage' => 'Enum("No,Yes")'
- );
- public static $has_one = array(
- 'WidgetImage' => 'Image',
- 'ImageLink' => 'SiteTree'
- );
- static $title = "";
- static $cmsTitle = "Image";
- static $description = "Add an image and optionally add a caption and link to a page on your website";
- public function getCMSFields() {
- return new FieldList(
- DropdownField::create('WidgetImageID','Image (225px or wider)', Image::get()->map())
- ->setEmptyString('--Select image--'),
- new TextField('ImageCaption','Caption (optional)'),
- new DropdownField('LinkToPage','Link to page?', singleton('ImageWidget')->dbObject('LinkToPage')->enumValues()),
- DropdownField::create('ImageLinkID','Link to page (optional)', SiteTree::get()->map())
- ->setEmptyString('--Select page--')
- );
- }
- }
- class ImageWidget_Controller extends Widget_Controller {
- public function WidgetImageLink($pageID){
- $page = SiteTree::get()->byID($pageID)->Link();
- if ($page) return $page;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement