Hey guys,
I thought this would be a very easy thing to accomplish, but have been struggling with this for hours now. Basically what I want to do is have a page type that lets you create a form (have all the functionality of UserDefinedForm), PLUS a file upload field to upload a PDF.
Isn't that just extending UserDefinedForm like this?:
<?php
class DokumentoPuslapis extends UserDefinedForm {
public static $has_one = array(
'Taisykles' => 'File'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.PDF', new UploadField('Taisykles'));
return $fields;
}
}
class DokumentoPuslapis_Controller extends UserDefinedForm_Controller {
public function init() {
parent::init();
}
}
Trying to access a newly created page of this type for editing gives me this:
[User Error] Couldn't run query: SELECT DISTINCT "SiteTree"."ClassName", "SiteTree"."Created", "SiteTree"."LastEdited", "DokumentoPuslapis"."TaisyklesID", CASE WHEN "SiteTree"."ClassName" IN ('SiteTree', 'Page', 'DokumentuKatalogas', 'KontaktuPuslapis', 'NaujienosPuslapis', 'NaujienuKatalogas', 'PagrindinisPuslapis', 'PereinantisPuslapis', 'ErrorPage', 'RedirectorPage', 'VirtualPage', 'UserDefinedForm', 'DokumentoPuslapis', 'DokumentuPuslapis') THEN "SiteTree"."Version" WHEN "SiteTree"."ClassName" IN ('UserDefinedForm', 'DokumentoPuslapis', 'DokumentuPuslapis') THEN "UserDefinedForm"."Version" ELSE NULL END AS "Version", "SiteTree"."ID", CASE WHEN "SiteTree"."ClassName" IS NOT NULL THEN "SiteTree"."ClassName" ELSE 'SiteTree' END AS "RecordClassName", "SiteTree"."Sort" FROM "SiteTree" LEFT JOIN "DokumentoPuslapis" ON "DokumentoPuslapis"."ID" = "SiteTree"."ID" WHERE ("DokumentoPuslapis"."ID" = 41) AND ("SiteTree"."ClassName" IN ('DokumentoPuslapis')) ORDER BY "SiteTree"."Sort" ASC LIMIT 1 Unknown column 'UserDefinedForm.Version' in 'field list'
GET /ss3/admin/pages/edit/show/41
Line 580 in C:\wamp\www\ss3\framework\model\MySQLDatabase.php
Might this have to do with me recently installing the Translatable module? Or is my code simply wrong?
EDIT: After some fiddling I came up with a partial solution.
<?php
class UDFDecorator extends DataExtension {
static $has_one = array(
'Taisykles' => 'File'
);
public function getCMSFields() {
$this->extend('updateCMSFields', $fields);
return $fields;
}
public function updateCMSFields(FieldList $fields) {
$fields->push(new UploadField('Taisykles', 'Prisegamas failas'));
}
}
_config.php:
Object::add_extension('UserDefinedForm', 'UDFDecorator');
Still, that makes ALL the forms have this functionality. Shouldn't extending the UDF class work?