Skip to content
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

Closed
silverstripesk opened this issue Jan 20, 2013 · 7 comments
Closed

Sorting on Extension classes #22

silverstripesk opened this issue Jan 20, 2013 · 7 comments
Labels

Comments

@silverstripesk
Copy link
Contributor

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

@UndefinedOffset
Copy link
Owner

This sounds like a deficiency in the core of SilverStripe that said I will test this when I can. Just to be sure ;)

@UndefinedOffset
Copy link
Owner

What version of SilverStripe were you using?

@silverstripesk
Copy link
Contributor Author

3.0.3

@UndefinedOffset
Copy link
Owner

Thanks ;)

@UndefinedOffset
Copy link
Owner

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');

@silverstripesk
Copy link
Contributor Author

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');
    }
}
?>

@silverstripesk
Copy link
Contributor Author

your module now works well with my carousel module: https://github.com/Silvermax/maxcarousel
Thanks for your great module!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants