New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sorting on Extension classes #22
Comments
This sounds like a deficiency in the core of SilverStripe that said I will test this when I can. Just to be sure ;) |
What version of SilverStripe were you using? |
3.0.3 |
Thanks ;) |
Is your extension extending DataExtension? or just Extension? The reason I ask is I just tried a test and it seemed to work as expected for me using the git master of SortableGridField and SS 3.0.3 stable. This was my setup: TestPage.php <?php
class TestPage extends Page {
public static $many_many=array(
'TestObjects'=>'TestObject'
);
public function getCMSFields() {
$fields=parent::getCMSFields();
$fields->addFieldToTab('Root.TestObject', $grid=new GridField('TestObjects', 'Test Objects', $this->TestObjects(), GridFieldConfig_RelationEditor::create(10)));
$grid->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
return $fields;
}
public function TestObjects() {
return $this->getManyManyComponents('TestObjects')->sort('SortOrder');
}
}
class TestPage_Controller extends Page_Controller {}
?> TestObject.php <?php
class TestObject extends Dataobject {
public static $db=array(
'Title'=>'Varchar'
);
public static $belongs_many_many=array(
'TestPages'=>'TestPage'
);
public function getCMSFields() {
return new FieldList(
new TextField('Title', 'Title')
);
}
}
?> TestPageExtension.php <?php
class TestPageExtension extends DataExtension {
public static $many_many_extraFields=array(
'TestObjects'=>array(
'SortOrder'=>'Int'
)
);
}
?> _config.php Object::add_extension('TestPage', 'TestPageExtension'); |
hi, im defining relation in DataExtension too... I tested your example in my situation and it works well! Thanks Ed! <?php
class TestPageExtension extends DataExtension {
public static $many_many_extraFields=array(
'TestObjects'=>array(
'SortOrder'=>'Int'
)
);
public static $many_many=array(
'TestObjects'=>'TestObject'
);
public function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab('Root.TestObject', $grid=new GridField('TestObjects', 'Test Objects', $this->owner->TestObjects(), GridFieldConfig_RelationEditor::create(10)));
$grid->getConfig()->addComponent(new GridFieldSortableRows('SortOrder'));
}
public function TestObjects() {
return $this->owner->getManyManyComponents('TestObjects')->sort('SortOrder');
}
}
?> |
your module now works well with my carousel module: https://github.com/Silvermax/maxcarousel |
Hallo,
im trying to sort many_many related data. Your code works great if I add relation to Page.php directly, but not, if i add the relation to Extension class which is extending Page class... :(
I think many_many_extraFields are not found :(
Regards
Pali
The text was updated successfully, but these errors were encountered: