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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Modyfying Modules PHP code: Best Practice


Reply


2 Posts   1379 Views

Avatar
tonito

Community Member, 24 Posts

31 August 2010 at 4:04am

I have modified Image_Gallery, Ecommerce and Blog modules php code extensively.

I was wondering what was the best practice for doing so.

For instance I created MyImageGalleryPage.php, that extends ImageGalleryPage.php. That's working fine. But more specifically, I also made changes to ImageGalleryItem.php. Can I create a MyImageGalleryItem.php that extends ImageGalleryItems.php. Will the modified "my" page be called? Will Silverstripe be able to complete the puzzle?

Also, as it stands, both Image Gallery Page and My Image Gallery Page pagetypes show in the CMS in the create dropdown menu. I would like to disable Image Gallery Page. I read somewhere that it was possible, but I cannot find the information again. What is the correct syntax?

Avatar
UncleCheese

Forum Moderator, 4094 Posts

31 August 2010 at 4:29am

Good question!

In general, you should never have to modify the source of a module. If you do, either the module isn't engineered very well, or you're not extending it the right way.

To answer your question about ImageGallery, to get it to talk to your ImageGalleryItem subclass, add:

protected $itemClass = "YourImageGalleryItemSubclass";

To your ImageGalleryPage subclass (MyImageGalleryPage in your case).

To hide the ancestor, you can add:

static $hide_ancestor = "ImageGalleryPage";

Hope this helps.

-------
Silverstripe tutorials, screencasts, tips, and more: http://www.leftandmain.com