Jump to:

7911 Posts in 1354 Topics by 930 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Go to End
Author Topic: 54215 Views
  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    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'
       );
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    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")

  • Chucky2k
    Avatar
    Community Member
    32 Posts

    Re: Preview: DataObjectManager module Link to this post

    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

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    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'
       );
    }

  • Anonymous user
    Avatar
    Community Member
    1 Post

    Re: Preview: DataObjectManager module Link to this post

    I'm not sure why UncleCheese proposed to set the parent class to Page, but did you try to setParentClass('QualityPDFPage')?

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    Good thought, ntessore. I don't think it will work, though, as there is no QualityPDFPageID column in the PDFResource table.

  • drye
    Avatar
    Community Member
    49 Posts

    Re: Preview: DataObjectManager module Link to this post

    bgribaudo, in my code and all the examples i have seen it is required to have a reference to your page type from the resource object. Are you sure you shouldn't have something like

    class QualityPDF extends PDFResource
    {
    static $has_one = array (
    'Page' => 'QualityPDFPage '
    );
    }


    and then you could setParentClass('QualityPDFPage')

    Good Luck, I'm no expert.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Yeah, the parent class has to be the one that's in your has_one relationship. Put it this way.. setParentClass() tells the table which ID field it will update. so setParentClass('Page') means it will try to update PageID on the object. setParentClass('QualityPDFPage') will try to update the field QualityPDFPageID.

    @David -- Thanks for these fixes. I've checked them in.

    54215 Views
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.