andrewhoule / silverstripe-photogallery

Simple photo gallery with albums for Silverstripe
BSD 3-Clause "New" or "Revised" License
11 stars 13 forks source link

Dataextension doesn't work well #4

Closed brasileric closed 8 years ago

brasileric commented 9 years ago

I want to add extra fields to PhotoItem dataobject by using dataextension. Below is my code, the extra fieds has been added to the database table, but in the cms the form fields doesn't appaer. Any idea what can be the cause? I added the dataextension to my config.yml as well and did /dev/build?flush=all

<?php

class CustomPhotoItem extends DataExtension {

private static $db = array (
    'CaptionEn' => 'Text',
    'CaptionDe' => 'Text'
);

private static $has_one = array (
);

public function updateCMSFields(FieldList $fields) {
    //$fields->addFieldToTab('Root.Main', new TextField('CaptionEn', 'Extra Text Field'),'Caption');
    $fields->push(new TextField('CaptionEn'));
    $fields->push(new TextField('CaptionDe'));

}

}

andrewhoule commented 9 years ago

Hmmm, I can't get this working on a test site either... Your code looks right though. I'll let you know if I figure it out. Alternatively, you could extend the page and dataobjects, but what you're trying to do is a much better method.

micmania1 commented 9 years ago

This is because you're not calling parent::getCMSFields() which contains the call to $this->extend('updateCMSFields', $fields);

updateCMSFields() isn't getting called.

Simple fix: $fields = FieldList::create(...); $this->extend('updateCMSFields', $fields); return $fields;

3Dgoo commented 9 years ago

This issue is fixed in pull request https://github.com/andrewhoule/silverstripe-photogallery/pull/3

andrewhoule commented 9 years ago

I just tested with the new pull request, the fields will show now.

camfindlay commented 8 years ago

Looks like this is resolved in #3 perhaps close out this issue :D