Hi,
I have a gallery module that i want decorate sitetree with so that all my pages have the photo gallery function in them (i.e blog, product page...they all must have the gallery module)
As i see it, this comprises of a 2 part solution.
1) GalleryPage extends DataExtension....this modifies the CMS etc. [b} I have this working already [/b}
2) GalleryPage_Controller extends Extension (and in my config file i add in Object::add_extension('ContentController', 'GalleryPage_Controller'); [b} This is not currently working and this is where i need help [/b}
Herewith the code i am currently using:
My _config.php file
// Extend the page class
SiteTree::add_extension('GalleryPage');
Object::add_extension('ContentController', 'GalleryPage_Controller');
My GalleryPage.php file
class GalleryPage extends DataExtension {
private static $db = array(
'GalFolder' => 'Varchar(100)'
);
private static $has_one = array(
);
// One gallery page has many gallery images
private static $has_many = array(
'GalleryImages' => 'GalleryImage'
);
// Set Permissions
function canEdit($Member = null){if(permission::check('EDIT_GALLERY')){return true;}else{return false;}}
function canCreate($Member = null){if(permission::check('EDIT_GALLERY')){return true;}else{return false;}}
// Get existing CMS Fields
public function getCMSFields() {
$this->extend('updateCMSFields', $fields);
return $fields;
}
// Update CMS with new fields
public function updateCMSFields(FieldList $fields) {
$gridFieldConfig = GridFieldConfig_RecordEditor::create();
$gridFieldConfig->addComponent(new GridFieldBulkUpload());
$gridFieldConfig->addComponent(new GridFieldBulkManager());
// Creates field where you can type in the folder name --- IT WILL CREATE IN ROOT OF ASSET DIRECTORY!!!
$fields->addFieldToTab("Root.ImageGallery", new TextField('GalFolder','Folder name')
);
// Used to determine upload folder
if($this->owner->GalFolder!='' || $this->owner->GalFolder!=NULL) {
// Specify the upload folder
$uploadfoldername = $this->owner->GalFolder;
$gridFieldConfig->getComponentByType('GridFieldBulkUpload')
->setUfSetup('setFolderName', $uploadfoldername)
->setUfConfig('sequentialUploads', true);
}
else {
$gridFieldConfig->getComponentByType('GridFieldBulkUpload')
->setUfSetup('setFolderName', 'Gallery-Images')
->setUfConfig('sequentialUploads', true);
}
// Customise gridfield
$gridFieldConfig->removeComponentsByType('GridFieldPaginator'); // Remove default paginator
$gridFieldConfig->addComponent(new GridFieldPaginator(20)); // Add custom paginator
$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder'));
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); // We only use bulk upload button
// Creates sortable grid field
$gridfield = new GridField("GalleryImages", "Image Gallery", $this->owner->GalleryImages()->sort("SortOrder"), $gridFieldConfig);
$fields->addFieldToTab('Root.ImageGallery', $gridfield);
return $fields;
}
// Check that folder name conforms to assets class standards. remove spaces and special charachters if used
function onBeforeWrite() {
$this->owner->GalFolder = str_replace(array(' ','-'),'-', preg_replace('/\.[^.]+$/', '-', $this->owner->GalFolder));
parent::onBeforeWrite();
}
}
class GalleryPage_Controller extends Extension implements PermissionProvider {
private static $allowed_actions = array (
);
public function init() {
parent::init();
//Load CSS requirements
Requirements::css("ss3Gallery/css/bootstrap-image-gallery.css");
Requirements::css("ss3Gallery/css/blueimp-gallery.min.css");
//Load Javascript requirements
Requirements::javascript("ss3Gallery/js/jquery.blueimp-gallery.min.js");
Requirements::javascript("ss3Gallery/js/bootstrap-image-gallery.min.js");
Requirements::javascript("ss3Gallery/js/blueimp-gallery-fullscreen.js");
// Call the blue imp jquery
Requirements::customScript("
document.getElementById('links').onclick = function (event) {
event = event || window.event;
var target = event.target || event.srcElement,
link = target.src ? target.parentNode : target,
options = {index: link, event: event},
links = this.getElementsByTagName('a');
blueimp.Gallery(links, options);
};
");
}
//Add permission check boxes to CMS
public function providePermissions() {
return array(
"VIEW_GALLERY" => "View Gallery Pages",
"EDIT_GALLERY" => "Edit Gallery Pages",
);
}
// Set sort order for images
public function GetGalleryImages() {
return $this->owner->GalleryImages()->sort("SortOrder");
echo "Hi Shaun";
}
}