-
-
Save hailwood/41b915c73190112378fb 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 CraftsPage extends Page { | |
static $has_many = array( | |
'Files' => 'ImageAndFile' | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
foreach (array('Files') as $field) { | |
$config = new GridFieldConfig_RelationEditor(); | |
$config->addComponent(new GridFieldSortableRows('SortOrder')); | |
$config->addComponent($uploader = new GridFieldBulkUpload()); | |
$uploader->setUfSetup('setFolderName', 'Uploads/Craft/Images'); | |
$config->addComponent(new GridFieldBulkManager()); | |
$config->addComponent(new GridFieldGalleryTheme('Image')); | |
$fields->addFieldToTab('Root.' . $field, new GridField($field, null, $this->{$field}(), $config)); | |
} | |
return $fields; | |
} | |
} | |
class CraftsPage_Controller extends Page_Controller { | |
} |
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 Partner | |
* | |
* @property String $Title | |
* @property Int $SortOrder | |
* @method Image Image() | |
* @method File File() | |
*/ | |
class ImageAndFile extends DataObject { | |
private static $db = array( | |
'Title' => 'Varchar', | |
'SortOrder' => 'Int' | |
); | |
public static $default_sort = 'SortOrder'; | |
private static $has_one = array( | |
'Image' => 'Image', | |
'File' => 'File', | |
'Page' => 'Page' | |
); | |
private static $summary_fields = array( | |
'Title', | |
'File.Title' | |
); | |
public function getCMSFields() { | |
$fields = parent::getCMSFields(); | |
/** @var Upload_Validator $validator */ | |
$validator = $fields->fieldByName('Root.Main.Image')->getValidator(); | |
$validator->setAllowedExtensions(array('jpg', 'png')); | |
$fields->removeFieldFromTab('Root.Main', 'SortOrder'); | |
return $fields; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment