Jump to:

7940 Posts in 1543 Topics by 946 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1344 Views
  • tonito
    Community Member
    24 Posts

    Modyfying Modules PHP code: Best Practice Link to this post

    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?

  • UncleCheese
    4085 Posts

    Re: Modyfying Modules PHP code: Best Practice Link to this post

    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

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.