Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Image gallery module


Go to End


6 Posts   1433 Views

Avatar
Sibot

Community Member, 3 Posts

4 June 2010 at 9:51pm

I have uploaded and installed the image gallery module (Uncle cheeses one) / swfupload etc etc .

My request is simple , I need to add another field underneath the "Caption" field called "Info" . Where can I do this ?

Thanks so much in advance !

SimonC

Avatar
UncleCheese

Forum Moderator, 4102 Posts

5 June 2010 at 2:21am

class MyImageGalleryPage extends ImageGalleryPage
{
protected $itemClass = "MyImageGalleryItem";
}

class MyImageGalleryItem extends ImageGalleryItem
{
static $db = array ('Foo' => 'Text');

public function getCMSFields_forPopup()
{
$f = parent::getCMSFields_forPopup();
$f->push(new TextField('Foo'));
return $f;
}
}

Avatar
Sibot

Community Member, 3 Posts

7 June 2010 at 10:36pm

Thanks uncle cheese for the quick response and also the code :)

But, Im fairly noob and have no idea what im doing wrong but I cant seem to get it to work ... this is what I have done .

1. Created a new file in imagegallery/code called ImageGalleryField.php
2. Copied the following code in the file :

<?php

class MyImageGalleryField extends ImageGalleryPage
{
protected $itemClass = "MyImageGalleryItem";
}

class MyImageGalleryItem extends ImageGalleryItem
{
static $db = array ('Foo' => 'Text');

public function getCMSFields_forPopup()
{
$f = parent::getCMSFields_forPopup();
$f->push(new TextField('Foo'));
return $f;
}
}

class MyImageGalleryField_Controller extends ImageGalleryPage_Controller {

}
?>

3. Ran dev/build

4. I am now getting errors ... http://www.pastie.org/994741

Thanks again for your help, and time :)

Simon C

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 June 2010 at 1:52am

No, no.. Never touch anything in the image_gallery directory. That's the whole point of subclassing -- so you don't have to hack the core code. All of these new files should be in your project directory.

In Silverstripe, your class names have to be the same as the .php file in which they are contained, so "ImageGalleryField.php" and "MyImageGalleryField" isn't going to work.

Just as a side note, it's a little unusual that you've named your subclass of ImageGalleryPage "ImageGalleryField?" You're subclassing the entire page type.. it has nothing to do with a field. Name it something that is relevant to your customization, for instance, if you're going to have a gallery of cars, call it "AutoGallery extends ImageGalleryPage"...

Avatar
Sibot

Community Member, 3 Posts

8 June 2010 at 7:58pm

Hi again, thanks for that . I see what you are saying ...

But I am still getting errors .

I have made the file in mysite/code/PetGalleryPage.php

<?php

class PetGalleryPage extends ImageGalleryPage
{
protected $itemClass = "MyImageGalleryItem";
}

class MyImageGalleryItem extends ImageGalleryItem
{
static $db = array ('Foo' => 'Text');

public function getCMSFields_forPopup()
{
$f = parent::getCMSFields_forPopup();
$f->push(new TextField('Foo'));
return $f;
}
}

class PetGalleryPage_Controller extends ImageGalleryPage_Controller {

}
?>

then ran dev/build

and get these :http://pastebin.com/6iKE8eGz

I just don't get what could be wrong here....

thanks again

Avatar
UncleCheese

Forum Moderator, 4102 Posts

9 June 2010 at 1:55am

Are all those in the same file? The page and its controller should be in one file, but the Item subclass needs to be in its own. Generally, in SS, it's one class per file.