frankmullenger / silverstripe-gallery

Image gallery for SilverStripe 3
23 stars 17 forks source link

Extending #3

Closed pinkp closed 10 years ago

pinkp commented 11 years ago

Hi Frank, I'm finding this module great except the latest version seems tricky to extend. For example to get another field for each image such as "PhotoTitle" I had to add the following. Seems a bit much, am I going about this the wrong way? (it works).

gallerypage.php

public function PhotoTitle() {

//TODO: Make this more generic and not require a db query each time
$controller = Controller::curr();
    $page = $controller->data();

$joinObj = GalleryPage_Images::get()
        ->where("\"GalleryPageID\" = '{$page->ID}' AND \"ImageID\" = '{$this->owner->ID}'")
        ->first();

    return $joinObj->PhotoTitle;

}


class GalleryPage_Images extends DataObject {

static $db = array (
'GalleryPageID' => 'Int',
'ImageID' => 'Int',
'Caption' => 'Text',
'SortOrder' => 'Int',
'PhotoTitle' => 'Text',

); }


public function getUploadFields() {

$fields = $this->owner->getCMSFields();

$fileAttributes = $fields->fieldByName('Root.Main.FilePreview')->fieldByName('FilePreviewData');
$fileAttributes->push(TextField::create('PhotoTitle', 'PhotoTitle:'));
$fileAttributes->push(TextareaField::create('Caption', 'Description:')->setRows(5));

galleryuploadfield.php

$data = array(
        'Caption' => $joinObj->Caption,
        'PhotoTitle' => $joinObj->PhotoTitle    
    );
    $form->loadDataFrom($data);

    $form->addExtraClass('small');
    return $form;
}
frankmullenger commented 10 years ago

Hi @pinkp I've changed the module now so that it is much easier to "extend" the gallery - or at least apply gallery functionality to any page type you like. Hopefully this is more flexible and sorts out this issue - please give the new 1.0 version a try and let me know!