Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How can I add stuff to the image class and show in popup?

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: 1446 Views
  • joelg
    Avatar
    Community Member
    129 Posts

    How can I add stuff to the image class and show in popup? Link to this post

    Hi

    I would like to know if anyone has tried adding fields to the image class?

    I've tried to use the DataObjectDecorator, and it works fine, but I'm not sure how to show/edit the $fields in the popup window.

    At the moment I have the default 4 fields (Name, Title, Filename and Content) and I just want to add my new fields to these.

    Can anyone help?

    Thanks many times.

    Joel

  • UncleCheese
    Avatar
    4085 Posts

    Re: How can I add stuff to the image class and show in popup? Link to this post

    What do you mean "image class?" For the ImageGallery module?

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: How can I add stuff to the image class and show in popup? Link to this post

    Well, that's the question... I'm pretty confused about this part, maybe this picture will explain it better:

    So basically I just want to add things to this popup window in the Files & Images part of the CMS... Does it make sense?

  • UncleCheese
    Avatar
    4085 Posts

    Re: How can I add stuff to the image class and show in popup? Link to this post

    Yeah, this is a minor bug right now. The AssetAdmin with DataObjectManager will not respect decorated File objects. It's a simple fix, and I had someone submit a patch, but when I went to check on it, the file had been removed. I hope to sort it out soon.

    But yes, you're right. You should be able to decorate the Image class and use updateCMSFields().

    For now, in dataobject_manager/_config.php, just set allow_asset_override(false);

    I'll repost to this thread when the fix is in.

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: How can I add stuff to the image class and show in popup? Link to this post

    Hi UncleCheese

    Thanks for a quick answer. You helped me in the right direction.

    I found a solution: First I extended the File class in mysite/_config.php, like this:

    Object::add_extension('File', 'GalleriPulsArtImage');

    Then I created the extended class:

    class GalleriPulsArtImage extends Extension
    {

       public function extraStatics() {
          return array(
             'db' => array(
                'Kategori' => "Enum('Link, Billede')"
             )
          );
       }
    }

    And last I edited AssetManager.php with an extra line i the $fields variable in the constructur:

    new DropdownField('Kategori','Kategori', singleton('File')->dbObject('Kategori')->enumValues()),

    It seems to work for now. Of course if there is a smarter solution please let me know.

    Thanks again.

    Joel

  • UncleCheese
    Avatar
    4085 Posts

    Re: How can I add stuff to the image class and show in popup? Link to this post

    You shouldn't hack the core code because when you update to a new version your changes will break. I've actually just made that update so if you run an update it should use your updateCMSFields() function now.

  • joelg
    Avatar
    Community Member
    129 Posts

    Re: How can I add stuff to the image class and show in popup? Link to this post

    Hi UncleCheese

    Thanks for a quick update. I installed it and here is some feedback/questions.

    I noticed that allow_asset_override is set to false per default in _config.php - however this just turns the dataObjectManager completely off in the Files & Images. Why? I just turned it back on with 'true'.

    The updateCMSFields function now works, however doing a SimpleTreeDropdownField returns a simple textfield with the ID in it... Here is my code for the extended class:

    class ExtendedImage extends Extension
    {

       public function extraStatics() {
          return array(
             'db' => array(
                'Kategori' => "Enum('Billede, Link')",
                'SiteLinkID' => 'Int'
             ),
             'has_one' => array(
                'SiteLink' => 'SiteTree',
                'BilledeThumb' => 'Image',
             ),
          );
       }
       
       public function updateCMSFields(FieldSet &$fields) {
          $fields->push(new DropdownField('Kategori','Kategori', singleton('File')->dbObject('Kategori')->enumValues()));
          $fields->push(new SimpleTreeDropdownField('SiteLinkID','Vælge en side (hvis kategorien er et link)'));
          $fields->push(new FileIFrameField('BilledeThumb'));
          return $fields;
       }
    }

    The last thing. In mysite/_config.php I've written:

    Object::add_extension('File', 'ExtendedImage');

    Now this works, the problem is that the extended class also shows up when I click on folders. See this photo which explains:

    I tried to change it to:

    Object::add_extension('Image', 'ExtendedImage');

    But with no luck, silverstripe just returns an error...

    Ok, I know, many question, but hope you can help. Thanks again.

    Joel

  • UncleCheese
    Avatar
    4085 Posts

    Re: How can I add stuff to the image class and show in popup? Link to this post

    You have conflicting fields in your model.

    'db' => array(
    'Kategori' => "Enum('Billede, Link')",
    'SiteLinkID' => 'Int'
    ),
    'has_one' => array(
    'SiteLink' => 'SiteTree',
    'BilledeThumb' => 'Image',
    ),

    You should remove SiteLinkID from your db array and leave it as a has_one. Right now, you have two fields fighting over the column "SiteLinkID"

    Run an update and see if it helps you with the other issues.

    1446 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.