Skip to content

Instantly share code, notes, and snippets.

@hailwood
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hailwood/32a131f9a16679125db1 to your computer and use it in GitHub Desktop.
Save hailwood/32a131f9a16679125db1 to your computer and use it in GitHub Desktop.
<?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;
}
}
<?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