Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How do I get ImageDataObjectManager to work?

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 4098 Views
  • lawless
    Avatar
    Community Member
    33 Posts

    Re: How do I get ImageDataObjectManager to work? Link to this post

    Did you do a /dev/build/ ?

  • Roweena
    Avatar
    Community Member
    28 Posts

    Re: How do I get ImageDataObjectManager to work? Link to this post

    yes I did

  • lawless
    Avatar
    Community Member
    33 Posts

    Re: How do I get ImageDataObjectManager to work? Link to this post

    Next stupid config question - have you installed swfupload?

    http://www.silverstripe.org/swfuploadfield-module/

    The imageDataObjectManager uses that to upload the images.

  • Roweena
    Avatar
    Community Member
    28 Posts

    Re: How do I get ImageDataObjectManager to work? Link to this post

    Yes I have I've been through all the instructions several times over.

  • lawless
    Avatar
    Community Member
    33 Posts

    Re: How do I get ImageDataObjectManager to work? Link to this post

    OK, enough with the dumb questions then. Here's code from my working example you can compare against:

    class SurfboardPage extends Page
    {
       static $has_many = array (
          'Surfboards' => 'Surfboard'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new ImageDataObjectManager(
             $this, // Controller
             'Surfboards', // Source name
             'Surfboard', // Source class
             'Attachment', // File name on DataObject
             array(
                'Dimensions' => 'Dimensions',
                'Shaper' => 'Shaper',
                'Price' => 'Price',
                'Category' => 'Category'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          
          $manager->setFilter(
             'Category', // Name of field to filter
             'Filter by Category', // Label for filter
             singleton('Surfboard')->dbObject('Category')->enumValues() // Map for filter (could be $dataObject->toDropdownMap(), e.g.)
          );
          
          // If undefined, all types are allowed. Pass with or without a leading "."      
          $manager->setAllowedFileTypes(array('jpg'));
          
          // Label for the upload button in the popup
          $manager->setBrowseButtonText("Upload (JPG only)");
          
          // In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
          $manager->setGridLabelField('Dimensions');
          
          // Plural form of the objects being managed. Used on the "Add" button.
          // If left out, this defaults to [MyObjectName]s
          $manager->setPluralTitle('Surfboards');
          
          // Set Upload folder to assets/uploads/boards
          $manager->setUploadFolder('assets/Uploads/boards');
                
          $f->addFieldToTab("Root.Content.Surfboards", $manager);

          return $f;
       }

    }

    class SurfboardPage_Controller extends Page_Controller
    {
    }

    I've got some extra variables at the end which shouldn't matter, but you may want to try adding the class at the end for the Controller, so in your example you'd add to the very end of your ResourcePage.php:

    class ResourcePage_Controller extends Page_Controller
    {
    }

    The only difference I noticed on what would be your Resource.php is this bit:

    static $has_one = array (
          'Attachment' => 'File',
          'SurfboardPage' => 'SurfboardPage'
       );

    The attachment type is File rather than Image. Worth a shot.

    Silverstripe frustrates the hell out me debugging it sometimes. Most of my solutions have come from digging through the forums. Hope this helps. Good luck.

  • Roweena
    Avatar
    Community Member
    28 Posts

    Re: How do I get ImageDataObjectManager to work? Link to this post

    Thanks so much for you help and sharing your code, I'll take a look and see if I can get mine to work

    4098 Views
Page: 1 2
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.