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

Object::useCustomClass with Image


Go to End


842 Views

Avatar
cjsewell

Community Member, 3 Posts

17 November 2014 at 2:13pm

Edited: 17/11/2014 2:17pm

Hi all,

I have been working on a Front End Editing module and made use of Object::useCustomClass to wrap the default HTMLText and Varchar forTemplate methods to inject some custom elements around values to enable all the magic.

I now want to be able to do the same with Image objects, but I am unable to override the forTemplate method....

This is a simplified version of what I have:
FrontEndImage.php

class FrontEndImage extends Image {

    public function forTemplate() {
        $value = parent::forTemplate();
        return "<span class='editable'>" . $value . "</span>";
    }

}

_config.php
Object::useCustomClass('Image', 'FrontEndImage', true);
// I have also tried Object::useCustomClass('Image', 'FrontEndImage');

My FrontEndImage class is never initiated and the forTemplate method on my class is never called.
I have tried adding breakpoints and stepping through Silverstripe and it seems it ignores my useCustomClass and uses the Image class directly.

So my questions are

  • Is there some limitation with useCustomClass on has_one and has_many realtions?
  • Or is this a bug?
  • Or am I missing something?

Any input would be appreciated!

Cheers