I use a pattern that I used to use many times, but when I click "Save" or "Save & Publish" images disappear from upload filed (like loosing linking between photo and page).
<?php
class AboutUsPage extends Page
{
private static $allowed_children = false;
public static $has_many = array(
'AboutUsPhotos' => 'AboutUsPhoto'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new Tab('AboutUsPhotosTab', _t('AboutUsPage.AboutUsPhotosTab', 'Zdjęcia')));
$fields->addFieldToTab('Root.AboutUsPhotosTab', $uploadFieldForPhotos = new UploadField("AboutUsPhotoPhotos", _t("AboutUsPage.AboutUsPhotosTab", "Zdjęcia")));
$uploadFieldForPhotos->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
$uploadFieldForPhotos->setAllowedMaxFileNumber(3);
return $fields;
}
}
class AboutUsPage_Controller extends Page_Controller
{
}
class AboutUsPhoto extends Image
{
public static $has_one = array(
'AboutUsPage' => 'AboutUsPage'
);
}
?>