Jump to:

7913 Posts in 1355 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: 54319 Views
  • Howard
    Avatar
    Forum Moderator
    215 Posts

    Re: Preview: DataObjectManager module Link to this post

    Perfect tested both with and without a custom setGridLabelField. Thanks!

  • Howard
    Avatar
    Forum Moderator
    215 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hello again,

    Four quick points,
    1 - setSingleTitle on DataObjectManager doesn't appear to be working... It doesn't error just displays the default
    2 - Is there an easyish way to change the width of the columns?
    3 - Is there a way to set the default view to be either list or grid?
    4 - Is there a way to have images that we upload to a FileDataObjectManager field be displayed as thumbnails (not icons) along side document icons in the grid view?

    Certainly don't feel like you have to add these features but thought I would ask if there is a way that I could get any or all of them working.

    Thanks for all you work

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hi, Howard,

    First, undo all the changes you made to the code, and do an SVN update.

    1 - setSingleTitle on DataObjectManager doesn't appear to be working... It doesn't error just displays the default

    ==> You may not understand the function of SingleTitle. It is the text that displays on confirmation of the record being saved. "Saved $SingleTitle successfully." To change the button text, use setAddTitle().

    2 - Is there an easyish way to change the width of the columns?

    ==> No, but that's a good suggestion. Right now, it is subject to the same equal width columns that a non-width defined table is subject to. This was a limitation of ComplexTableField, as well. I could envision something like this:

    $manager->setColumnWidths(array(
    'Name' => '20',
    'Description => '60',
    'Date' => '20'
    ));
    // Expressed as percentages

    3 - Is there a way to set the default view to be either list or grid?

    ==> $manager->setDefaultView('list'); or $manager->setDefaultView('grid');

    4 - Is there a way to have images that we upload to a FileDataObjectManager field be displayed as thumbnails (not icons) along side document icons in the grid view?

    ==> This is something I'm really struggling with. Here's the problem. You've defined your object to have a $has_one with a File. So on upload, it creates a new object of the class you've specified -- File. Plain File objects, of course, don't get the image resizing functionality, so you're stuck with an icon. One thought is to evaluate the extension of the file on upload and force class Image if it's a JPG. But then you're disregarding the class that was spec'd in the DataObject. If someone had, for instance, a custom File or Image class, now they get stuck with Image, which they didn't ask for.

    I know there has to be some latitude there -- evaluating class ancestry, etc.. I hope to figure something out soon, because I agree, it would be nice.

    Thanks again for your feedback. Let me know how you do with those updates.

  • Bo_Einzeller
    Avatar
    Community Member
    18 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hi UncleCheese
    You could check if the file has the Resizing-Method. This would also be true, if there's a custom class which extends image.
    Use $file->hasMethod('croppedImage') to evaluate if its an Image-Class or not.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Understood, but if the file is added with ClassName "File," that will never return true. The problem is that files with extension .jpg get added as $file = new $className, where $className is the class of the $has_one relationship (most of the time, File).

    It's a question of whether we want to force the Image class on file types that, for all intents and purposes, should be store as Image objects. The Files and Images section of SS does this, but gets away with it because it's not managing relationships. When you change the class name of a related object, you're adding a lot of risk, and i could see it breaking stuff pretty easily.

  • pcbender
    Avatar
    Community Member
    20 Posts

    Re: Preview: DataObjectManager module Link to this post

    Thanks for the reply.

    The call to $Attachment.Type returns no value in the example below:

    <% if Resources %>
             
       <ul>
       <% control Resources %>
          <li><a href="$Attachment.URL">Download $Name $Attachment.Size and $Attachment.Type and $Category</a></li>
       <% end_control %>
       </ul>
    <% end_if %>

    Off Topic:

    Is there some way to programatically identify the fields and methods available to a view or template? For example:

    <% if Resources %>
       $ShowMembers
       <ul>
       <% control Resources %>
          <li><a href="$Attachment.URL">Download $Name $Attachment.Size and $Attachment.Type and $Category</a></li>
       <% end_control %>
       </ul>
    <% end_if %>

    The $ShowMembers call would return a list of members callable from the view.

    THanks,

    PC

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    As far as the Type property is concerned, I was just taking a guess. I'm not really sure of all the properties available for the File class. Check the docs/API.

    By creating a function such as $ShowMembers, you're breaking the MVC pattern by bundling presentation into your controller. That's what control blocks are for.

    <% control Members %>
    <li>$Name</li>
    <% end_control %>

    Edit: sorry. I misread your request, thinking you meant Members as in users. I would look at the "Built in template controls" topic in the docs first. Anything beyond that is accessible in either the model or controller of your page or object as a property or method.

    public $MyProperty = "foo"
    public function MyFunction() {
    return "bar";
    }

    $MyProperty $MyFunction

    returns "foo bar"

    Further, any named relation in your model gets a magic method.

    $has_many = array ('Objects' => 'MyClass');

    now grants you the function

    $this->Objects();

    Or on the template:

    <% control Objects %>

  • pcbender
    Avatar
    Community Member
    20 Posts

    Re: Preview: DataObjectManager module Link to this post

    Thank you very much. You are a tremendous asset to the SS community.

    BTW, it is $Attachment.FileType

    PC

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