Last active
August 29, 2015 14:10
-
-
Save hailwood/32a131f9a16679125db1 to your computer and use it in GitHub Desktop.
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 GalleryImage extends DataObject { | |
private static $db = array( | |
'Title' => 'VarChar', | |
'ObjectDescription' => 'Text', | |
'SortOrder' => 'Int' | |
); | |
public static $default_sort = 'SortOrder'; | |
private static $has_one = array( | |
'Image' => 'Image', | |
'Page' => 'Page' | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
$fields->fieldByName('Root.Main.Image') | |
->getValidator()->setAllowedExtensions(array('jpg', 'png')); | |
$fields->removeFieldFromTab('Root.Main', 'SortOrder'); | |
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
<?php | |
/** | |
* Base page type | |
* | |
* @method HasManyList HeaderImages() | |
* @method HasManyList GalleryImages() | |
*/ | |
class Page extends SiteTree { | |
#region Relationships | |
/** | |
* One to one relations | |
* @var array | |
*/ | |
private static $has_one = array( | |
); | |
/** | |
* One to many relations | |
* @var array | |
*/ | |
private static $has_many = array( | |
'HeaderImages' => 'GalleryImage', | |
'GalleryImages' => 'GalleryImage' | |
); | |
#endregion Relationships | |
#region Public Methods | |
public function getCMSFields(){ | |
$fields = parent::getCMSFields(); | |
foreach(array('HeaderImages', 'GalleryImages') as $field) { | |
$config = new GridFieldConfig_RelationEditor(); | |
$config->addComponent(new GridFieldSortableRows('SortOrder')); | |
$config->addComponent($uploader = new GridFieldBulkUpload()); | |
$uploader->setUfSetup('setFolderName', $field); | |
$config->addComponent(new GridFieldBulkManager()); | |
$config->addComponent(new GridFieldGalleryTheme('Image')); | |
$fields->addFieldToTab('Root.'.$field, new GridField($field, null, $this->{$field}(), $config)); | |
} | |
return $fields; | |
} | |
#endregion Public Methods | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment