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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Can I access data from getCMSFields?


Go to End
Reply


3 Posts   342 Views

Avatar
Raver0124

Community Member, 8 Posts

18 September 2013 at 3:03pm

Edited: 18/09/2013 3:04pm

Hi guys,

I'm new in SilverStripe and i'm not quite sure i can do this.
Can i access the data from getCMSField?

class ImageDemo extends Page 
{
    static $db = array(
        'Title'             => 'Varchar'
    );

    static $has_one = array(
        'Graphic'           => 'Image'
    );

    public function getCMSFields($params = null){
        $fields = parent::getCMSFields($params);

        if ($this->Graphic.exists()) {  <--------------- I wanna check if the data exist in Graphic


            $fields->addFieldToTab("Root.Content.Main", new UploadField('Graphic', "A Feature Image"), "Content");
            
        }
        else
        {
            $fields->addFieldToTab("Root.Content.Main", new TextField('Graphic', "A Feature Image"), "Content");
        }
        return $fields;
    }
}

Avatar
Willr

Forum Moderator, 5521 Posts

18 September 2013 at 8:59pm

The answer is sometimes. You can for edit forms but on creation the form values will not be set. You could do something like if($this->Graphic() && $this->Graphic()->exists()) { // ...

Avatar
Raver0124

Community Member, 8 Posts

19 September 2013 at 12:37pm

Thank you very much, that worked perfectly :)