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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Sortable Data Object at a loss


Reply


7 Posts   1513 Views

Avatar
Ctr

Community Member, 6 Posts

3 November 2010 at 7:58pm

Edited: 03/11/2010 8:00pm

I'm hoping I can get a bit of direction on this, hopefully I'm just missing something obvious.

I'm trying to integrate the sortable data object functionality. I have in my

/mysite/_config
SortableDataObject::add_sortable_classes(array('Link'));

I've run the flush and the new SortOrder column was created fine.

Nothing happens on the front end though.

So I've added this to the template, /themes/mytheme/templates/Includes/Links.ss
{$Links.BeginSortableUL}
<% if Links %>
<% control Links %>
{$LI}
<% if ExternalLink %>
<a href="$ExternalLink" target="_blank">$LinkTitle</a>
<% else %>
<a href="$Link.Link">$LinkTitle</a>
<% end_if %>
<br />
{$_LI}
<% end_control %>
<% end_if %>
{$Links.EndSortableUL}

Still no changes.

So then I thought maybe I need to use add_sortable_many_many_relation, because it is.
From /mysite/Page.php
   
static $has_many = array(
'Blocks' => 'Block',
'Links' => 'Link'
);

$tablefield = new DataObjectManager(
$this,
'Links',
'Link',
array(
// 'LinkedPage' => 'Internal Link',
// 'ExternalLink' => 'External Link',
'LinkTitle' => 'Link Text'
),
'getCMSFields_linkPopup'
);
$fields->addFieldToTab('Root.Content.Links', $tablefield);

/mysite/LinkPage.php
<?php
class Link extends DataObject{

static $db = array(
'ExternalLink' => 'Text',
'LinkTitle' => 'Text'
);

static $has_one = array(
'Page' => 'Page',
'Link' => 'SiteTree'
);

function getCMSFields(){

return new Fieldset(
new TreeDropdownField('LinkID','Internal Link','SiteTree'),
new TextField('ExternalLink','External Link (overrides internal link)'),
new TextField('LinkTitle')
);
}
}
?>

So I change my _config.php to
SortableDataObject::add_sortable_many_many_relation('Page','Link');
or also try
SortableDataObject::add_sortable_classes(array('Link'));
SortableDataObject::add_sortable_many_many_relation('Page','Link');
as I'm not quite sure what the correct syntax is.

Then I get this error (with either of the above entries in _config.php):

Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in /public_html/aston/sapphire/core/Object.php:385 Stack trace: #0 /public_html/aston/sapphire/core/Object.php(385): ReflectionClass->__construct('') #1 /public_html/aston/sapphire/core/Object.php(543): Object::uninherited_static(NULL, 'extensions') #2 /public_html/aston/dataobject_manager/code/SortableDataObject.php(19): Object::add_extension(NULL, 'SortableDataObj...') #3 /public_html/aston/dataobject_manager/code/SortableDataObject.php(52): SortableDataObject::add_sortable_class(NULL) #4 /public_html/aston/mysite/_config.php(40): SortableDataObject::add_sortable_many_many_relation('Page', 'Link') #5 /var/tmp/silverstripe-cache-home1-resolut1-public_html-aston/manifest-main(8249): require_once('/home1/resolut1...') #6 /public_html/aston/sapphire/core/ManifestBuilder.php(74): require_once('/var/tmp/silver...') #7 /home1/resolut1 in /public_html/aston/sapphire/core/Object.php on line 385

This on a otherwise blank screen.

I'm using 2.4.2, and I flush the front and db regularly.

Any help would be much appreciated!

Avatar
UncleCheese

Forum Moderator, 4096 Posts

4 November 2010 at 10:37am

Oh, man.. that's super old-school code. Where did you see the "BeginSortableUL" stuff? That hasn't existed for over two years.

SortableDataObject will automatically sort objects by their SortOder field by decorating the default_sort property of the object. The frontend UI stuff is loooooooooong gone. Never worked.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Ctr

Community Member, 6 Posts

4 November 2010 at 10:46am

Edited: 04/11/2010 10:49am

Hi Uncle Cheese!

First off, I'm a big fan, thanks for all the great modules you've crafted.

I tried it without the code in the template and I still can't get anything to happen on the front end, I must be missing something obvious.

This is my _config.php code now:
SortableDataObject::add_sortable_classes(array('Link'));

Then my frontend template is
<% if Links %>
<% control Links %>
<% if ExternalLink %>
<a href="$ExternalLink" target="_blank">$LinkTitle</a>
<% else %>
<a href="$Link.Link">$LinkTitle</a>
<% end_if %>
<br />
<% end_control %>
<% end_if %>

This is where I originally got the templating code:
http://doc.silverstripe.org/modules:sortabledataobject

Originally I followed the instructions that make more sense for the current setup from
http://doc.silverstripe.org/modules:dataobjectmanager
under the 'Activate Drag and Drop Sorting'

I don't see any changes on the front end.

When I add /sort to the url, I get 'Page not Found'. I'm sure that it gets as far as the add_sortable_classes function in the SortableDataObject.php file.

I'm not sure what else I should do to make this start working?

Thanks so much for you earlier response!

Avatar
Ryan M.

Community Member, 309 Posts

4 November 2010 at 12:59pm

Are you returning the Links via a custom function? If so, you might have something like this:

DataObject::get("Link", "", "Created DESC");

If you have any kind of sorting defined, it'll override the sorting set by the DOM. Just remove it and it'll display in the order that you defined.

Avatar
Ctr

Community Member, 6 Posts

4 November 2010 at 1:57pm

Thanks for replying Ryan-

I'm not using any custom functions to get this dataobject, just this:

<?php
class Link extends DataObject{

static $db = array(
'ExternalLink' => 'Text',
'LinkTitle' => 'Text'
);

static $has_one = array(
'Page' => 'Page',
'Link' => 'SiteTree'
);

function getCMSFields(){

return new Fieldset(
new TreeDropdownField('LinkID','Internal Link','SiteTree'),
new TextField('ExternalLink','External Link (overrides internal link)'),
new TextField('LinkTitle')
);
}
}
?>

Avatar
UncleCheese

Forum Moderator, 4096 Posts

5 November 2010 at 2:52am

Edited: 05/11/2010 2:52am

You might be misunderstanding how the module works. It's a decorator that's used in conjunction with the DataObjectManager module to allow drag-and-drop re-ordering. There is no frontend interface.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Ctr

Community Member, 6 Posts

5 November 2010 at 4:32am

Oh wow, doh!

You're right it is working effortlessly on the backend, probably has been this whole time.

Thanks for your patience, and the great modules!