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

Sort Order Not Working


Go to End


1603 Views

Avatar
Media Contour

Community Member, 33 Posts

18 February 2012 at 2:12pm

Edited: 21/02/2012 7:36am

Please reference code below.

I'm able to sort the CatalogProducts in the admin but it does not get rendered in the HomePage by the sort order. I'm not sure what the problem is as the sort order gets saved in the admin. What is it sorting by? Why is it sorting by that?

_config.php

SortableDataObject::add_sortable_classes(array('CatalogProduct'));

CatalogProduct.php

class CatalogProduct extends Page {
	static $belongs_many_many = array('HomePage' => 'HomePage');
}

class CatalogProduct_Controller extends Page_Controller {}

HomePage.php

class HomePage extends Page {
	public static $many_many = array('CarouselProducts' => 'CatalogProduct');
	
	function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$carousel = new ManyManyDataObjectManager(
			$this,
			'CarouselProducts',
			'CatalogProduct',
			array('Title' => 'Title'),
			'getCMSFields_forPopup'
		);
		$fields->addFieldToTab('Root.Content.CarouselProducts', new LiteralField('Carousel Products Break', '<br />'));
		$fields->addFieldToTab('Root.Content.CarouselProducts', new LabelField('Carousel Products Label', 'Carousel Products'));
		$fields->addFieldToTab('Root.Content.CarouselProducts', $carousel);
		
		return $fields;
	}
}

class HomePage_Controller extends Page_Controller {
	public static $allowed_actions = array ();

	public function init() {
		parent::init();
	}
}

HomePage.ss

<% control CarouselProducts %>
	<a href="$Link">$Title</a>
<% end_control %>