Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

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

New Module: SortWeight - Easy Ordering of DataObjects & Relationships


Reply


12 Posts   2782 Views

Avatar
swaiba

Forum Moderator, 1798 Posts

23 July 2011 at 2:46am

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

Avatar
swaiba

Forum Moderator, 1798 Posts

29 September 2011 at 10:00pm

Edited: 29/09/2011 10:33pm

*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
Avatar
brice

Community Member, 51 Posts

5 October 2011 at 5:34am

Edited: 05/10/2011 5:35am

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

Avatar
swaiba

Forum Moderator, 1798 Posts

5 October 2011 at 6:08am

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