Thanks for your fast reply! I've tested it and everything's fine. Great work!
I've tested the translation, if your interested, i could send you the german translation-File.
Cheers
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
DataObjectManager Module /
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
Preview: DataObjectManager module
Hello Everyone,
I would like to use FileDataObjectManager to relate files to a given page. Example: page a is associated with 'File1.pdf' and 'File6.pdf', page b is associated with other files, etc.
The problem I've hit is that the FileDataObjectManager in the QualityPDFPage below shows all files associated with any page, not just those files associated with the given page.
Any ideas on what I'm doing wrong?
Thanks!
Ben
class QualityPDFPage extends QualityChildPage {
static $has_many = array(
'PDFResource' => 'PDFResource'
);
static $db = array();
static $can_be_root = false;
static $allowed_children = array();
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'PDFResource', // Source name
'PDFResource', // Source class
'PDF',
array(
'Name' => 'Name'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
);
$fields->addFieldToTab('Root.Content.Resources', $manager);
$fields->removeFieldFromTab("Root.Content.Main", "Content");
return $fields;
}
}
Is QualityPDFPage the only page type that uses the FileDataObjectManager? Or is it used in another class as well? If so, you need to use the setParentClass() method.
Can you post your PDFResource class?
No, it's not the only class that uses FileDataObjectManager. I'll try setParentClass().
Here's PDFResource:
class PDFResource extends DataObject
{
static $db = array (
'Name' => 'Varchar(30)'
);
static $has_one = array (
'Thumbnail' => 'Image',
'PDF' => 'PDF', // this class is an extension of File which adds the ability to generate a thumbnail of the PDF's first page.
'Page' => 'Page'
);
}
Yeah, you need to because $has_one Page is too ambiguous. It's going to try to set QualityPDFPageID on your object, which is a field that doesn't exist, so you wont' get the relation. Make sure you set your FileDataObjectManager object to ->setParentClass("Page")
Hi Uncle Cheese,
Checked out the latest today and noticed a few issues. Looks like revision 82 has caused a couple of issues with DataObjectManager.php. On line 288 I changed from:
$dropdown = new DropdownField('Filter',$this->filter_label . " (<a href='#' class='refresh'>'._t('DataObjectManager.REFRESH','refresh').'</a>)", $map, $value);
to:
$dropdown = new DropdownField('Filter',$this->filter_label . " (<a href='#' class='refresh'> "._t('DataObjectManager.REFRESH','refresh')."</a>)", $map, $value);
Also, the removal of...
protected $view = "list";
and the public function ListStyle() causes the DataObjectManager Tab layout and the Albums Tab layout on an ImageGalleryPage to break.
David
Uncle Cheese,
Thanks for the help. Still no go. With --
$manager->setParentClass('Page');
-- no files show up in the file data object manager. Of note, PageID in the database table pdfresource is being set to zero. I'm guessing that if we figured out how to get field PageID to be set to the correct value, things might work. Any ideas?
Revised code below.
Thank you,
Ben
--------------
Revised Code:
class QualityPDFPage extends QualityChildPage {
static $has_many = array(
'PDFResource' => 'PDFResource'
);
static $db = array();
static $can_be_root = false;
static $allowed_children = array();
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'PDFResource', // Source name
'PDFResource', // Source class
'PDF',
array(
'Name' => 'Name'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
);
$manager->setParentClass('Page');
$fields->addFieldToTab('Root.Content.Resources', $manager);
$fields->removeFieldFromTab("Root.Content.Main", "Content");
return $fields;
}
}
class PDFResource extends DataObject
{
static $db = array (
'Name' => 'Varchar(30)'
);
static $has_one = array (
'PDF' => 'PDF',
'Page' => 'Page'
);
}
Good thought, ntessore. I don't think it will work, though, as there is no QualityPDFPageID column in the PDFResource table.