Jump to:

10993 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » New Module: SortWeight - Easy Ordering of DataObjects & Relationships

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 2718 Views
  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    Can this be used in ModelAdmin? I've got the module, added the init and it doesn't do anything to the scaffolded has_many items...

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    *bump*

    Brice? Please help your module looks awesome and I'd love to get it working!
    here is my code (and attached) with a fresh 2.4.5 install....

    <?php
    class DataObjectA extends DataObject {
       static $db = array(
          'Name' => 'Varchar'
       );
       static $has_many = array(
          'DataObjectB' => 'DataObjectB'
       );
    }

    <?php
    class DataObjectB extends DataObject {
       static $db = array(
          'Name' => 'Varchar'
       );
       static $has_one = array(
          'DataObjectA' => 'DataObjectA'
       );
    }

    <?php
    class MyAdmin extends ModelAdmin {
       static $managed_models = array(
          'DataObjectA',
       );
       static $url_segment = 'myadmin';
       static $menu_title = 'MyAdmin';
    }

    Attached Files
  • brice
    Avatar
    Community Member
    51 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    swaiba,

    Have you specified sort-weight should be added between DataObjectA and DataObjectB *before initializing*?

    The module's _config.php should read;

    SortWeightRegistry::decorate('DataObjectA','DataObjectB');
    SortWeightRegistry::set_module_path(basename(dirname(__FILE__)));

    I also believe I have an experimental version somewhere (will have to check when I return home) that I was working out some bugs on. I never committed this module as I still wasn't happy with the ability to tap into Complex Table Fields (core doesn't allow for an "onConstruct" callback of Objects, and the CTF doesn't provide any useful extension points). As a workaround it probably makes sense to use a SortableComplexTableField for displaying relations; but I wanted this module to be "plug-n-play" w/o having devs change anything. The 3.0 version of SilverStripe will feature a very nice grid to replace ComplexTableField/TableListField which I am sure will provide the best interface going forward. For 2.0 there's the DataObjectManager module which supports sortable -- and hopefully SortWeight as a more light-weight & SS-friendly alternative. Let me know if it works.

    ~ Brice

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: New Module: SortWeight - Easy Ordering of DataObjects & Relationships Link to this post

    Hi Brice,

    Thank you for getting back to me and yes I do already have the config line you have mentioned.

    If it were a SortableComplexTableField then it would be great - then I could ensure it's use instead of relying of on the automatic replacement.

    I understand that SS3 Datagrid will replace CTF (when it is stable) and also that the DOM has this functionality. However for this project I avoid using any large modules (only like to integrate small modules into it instead into the codebase) also since it's a big project it is likely I will continue with CTF for a while (as SS have indicated legacy will work so I assume CTF will become a module, just like the old time fields).

    Thanks again for you help

    Barry

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