7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Modyfying Modules PHP code: Best Practice
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 881 Views |
-
Modyfying Modules PHP code: Best Practice

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?
-
Re: Modyfying Modules PHP code: Best Practice

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
| 881 Views | ||
|
Page:
1
|
Go to Top |

