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

HasManyFileManager getMyCMSFields not called


Go to End


1655 Views

Avatar
tilluigi

Community Member, 9 Posts

15 January 2009 at 11:41pm

Hi there,

we are trying to get the hasmanyfilemanager (HMFM) to work with a custom file class, but the CMS interface does not show the extra fields defined by the getMyCMSFIelds-Function in the "MyFile"-class. it seems as if the getMyCMSFields function is not beeing called at all?

the basic HMFM works and the extra fields have been added to the database table of "File", so the decoration seems to have happened, at least on the Model side of things.

we are using the basic example for custom file class from the HMFM-tutorial and changed the extraDBFields according to our needs. the only other difference i can see is that we are applying the HMFM to a HomePage-Class wich is subclassed from Page. Heres the MyFile-Class:

class MyFile extends DataObjectDecorator
{
    /**
     * Adding additional DB Fields to the File Table.
     * @see http://doc.silverstripe.com/doku.php?id=dataobjectdecorator
     * 
     * @return array containing additional DB information
     */
    public function extraDBFields() {
        return array(
            'db' => array(
                'isFavorite' => 'Boolean',
                'Description' => 'Varchar(255)',
                'Category' => "Enum('photography, graphics, painting, other', 'photography')"
            )
        );
    }
 
    /**
     * Get the custom CMS Fields for this Class (to be used by the
     * HasManyFileManager).
     * As you can see we make a distinction between Images and other files!
     *
     * @return FieldSet
     */
    public function getMyCMSFields(){
		// trying to find out if function is being called:
		echo "TEST";
		
		if($this->owner instanceof Image){
            return new FieldSet(
 				new TextField(
                    'Title', 
                    'Title', 
                    $this->owner->ID ? $this->owner->Title : ''

                ),
                new TextField(
                    'Description',
                    'Short Description',
                    $this->owner->ID ? $this->owner->Description : ''
                ),
                new DropdownField(
                    'isFavorite', 
                    'is this a favorite?', 
                    array(1=> 'Yes', 0 => 'No'), 
                    $this->owner->ID ? $this->owner->isFavorite : 0
                ),
                new DropdownField(
                    'Category', 
                    'Category', 
                    singleton('File')->dbObject('Category')->enumValues(), 
                    $this->owner->ID ? $this->owner->Category : 0
                )
            );
        } else {
            return new FieldSet(
                new TextField('Title', 'Title', $this->owner->Title)
            );
        }
		
    }

}

we are running SS 2.2.3, it seems that HMFM has only been tested with 2.2.2 and does not work with 2.3rc at all.

anybody can help? anyone has had the same problem?