Hello there!
I'm trying to build a simple image gallery.
I created an GalleryImage DataObject that has a has_one relation to GalleryPage. I would like to be able to specify a folder name that is formed from the id and / or name of the related GalleryPage.
I know I can set the folder with
$uploadField->setFolderName('my_folder');
However…how do I access the properties of the related page in this context?
<?php
class BikeImage extends DataObject {
const TITLE_NAME = 'Title';
const SORT_ORDER_NAME = 'SortOrder';
private static $db = array(
self::TITLE_NAME => 'Varchar',
self::SORT_ORDER_NAME => 'Int',
);
// One-to-one relationship with bike page
private static $has_one = array(
'Image' => 'Image',
'GalleryPage' => 'GalleryPage'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Main', 'GalleryPageID');
$custom_folder_name = 'default';
// $custom_folder_name = name / id of related gallery page
// how to access the properties of the related gallery page?
$uploadField = new UploadField('Image', _t('general.image', 'image'));
$uploadField->setFolderName($custom_folder_name);
$fields->addFieldToTab('Root.Main', $uploadField);
return $fields;
}
// Tell the data grid what fields to show in the table
private static $summary_fields = array(
'ID' => 'ID',
self::TITLE_NAME => 'Title'
);
}
Thx for any pointers!