ENHANCEMENT Using new UploadField in ForeignKey scaffolding, replacing deprecated ImageField/FileField classes

This commit is contained in:
Ingo Schommer 2012-03-01 12:00:03 +01:00
parent 23bd11281d
commit c3f4db1d7d

View File

@ -31,17 +31,10 @@ class ForeignKey extends Int {
$hasOneClass = $this->object->has_one($relationName); $hasOneClass = $this->object->has_one($relationName);
if($hasOneClass && singleton($hasOneClass) instanceof Image) { if($hasOneClass && singleton($hasOneClass) instanceof Image) {
if(isset($params['ajaxSafe']) && $params['ajaxSafe']) { $field = new UploadField($relationName, $title);
$field = new ImageField($relationName, $title, $this->value); $field->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
} else {
$field = new SimpleImageField($relationName, $title, $this->value);
}
} elseif($hasOneClass && singleton($hasOneClass) instanceof File) { } elseif($hasOneClass && singleton($hasOneClass) instanceof File) {
if(isset($params['ajaxSafe']) && $params['ajaxSafe']) { $field = new UploadField($relationName, $title);
$field = new FileIFrameField($relationName, $title, $this->value);
} else {
$field = new FileField($relationName, $title, $this->value);
}
} else { } else {
$titleField = (singleton($hasOneClass)->hasField('Title')) ? "Title" : "Name"; $titleField = (singleton($hasOneClass)->hasField('Title')) ? "Title" : "Name";
$map = DataList::create($hasOneClass)->map("ID", $titleField); $map = DataList::create($hasOneClass)->map("ID", $titleField);