Created
June 25, 2014 09:41
-
-
Save camfindlay/af531b60502888b07529 to your computer and use it in GitHub Desktop.
Custom SiteConfig for Sponsor Links and Logos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SiteConfig: | |
extensions: | |
- CustomSiteConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CustomSiteConfig extends DataExtension { | |
private static $has_many = array( | |
'Sponsors' => 'Sponsor' | |
); | |
public function updateCMSFields(FieldList $fields) { | |
$config = GridFieldConfig_RecordEditor::create(); | |
$sponsorfield = GridField::create( | |
'Sponsors', | |
'Sponsors', | |
$this->owner->Sponsors(), | |
$config | |
); | |
$fields->addFieldToTab('Root.Sponsors', $sponsorfield); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Sponsor extends DataObject { | |
private static $db = array ( | |
'Link' => 'Varchar(255)', | |
); | |
private static $has_one = array ( | |
'SiteConfig' => 'SiteConfig', | |
'Image' => 'Image', | |
); | |
private static $summary_fields = array( | |
"Image.CMSThumbnail", | |
"Link" | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
$fields->addFieldToTab('Root.Main', TextField::create('Link')); | |
$sizeMB = 2; // 2 MB | |
$size = $sizeMB * 1024 * 1024; // 2 MB in bytes | |
$uploadField = UploadField::create('Image', 'Sponsor Image'); | |
$uploadField->getValidator()->setAllowedMaxFileSize($size); | |
$fields->removeByName('SiteConfig'); | |
$fields->addFieldToTab('Root.Main', $uploadField); | |
return $fields; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% loop $SiteConfig.Sponsors %> | |
<p><a href="$Link">$Image.SetWidth(150)</a></p> | |
<% end_loop %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment