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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

SortOrder increment before addFieldToTab


Go to End


2 Posts   1217 Views

Avatar
nicanor

Community Member, 15 Posts

26 October 2011 at 12:47am

Edited: 26/10/2011 12:52am

I can get SortOrder Value in Admin Backend with SortOrder in DataObjectManager array like this:

$f->addFieldToTab("Root.Content.Mysite", new DataObjectManager(

			$this,

			'Persons',

			'PersonObject',

			array('Thumb' => 'Thumb','Name' => 'Name','Url' => 'Url','Category'=>'Category','Languages'=>'Languages','Countries' => 'Countries','SortOrder' => 'SortOrder'),

					'getCMSFields_forPopup'

			));

I have no idea how to increment the value in this Page Model. How can i access SortOrder before addFieldToTab?

Avatar
nicanor

Community Member, 15 Posts

27 October 2011 at 2:03am

I added a function to the corresponding Data Object.

Like described in datamodel http://doc.silverstripe.org/sapphire/en/topics/datamodel i have overwritten the getSortOder funct.

function getSortOrder() {
      
      // SortOrder is not working
      //return $this->SortOrder;

     return->Name;
}

But i can not access the field SortOrder. With Name, like in the code it works.

i thought it could be perhaps

$this->Sort
$this->Order

but don't work.

I have not defined SortOrder, this field is from Dataobjectmodel auto generated per _config.php

SortableDataObject::add_sortable_class('PersonObject');

In Admin Backend first element shows nothing because SortOrder=0. That's why i like to override getSortOrder with - something like -

return ($this-SortOrder+1);