Reputation: 185
I am attempting to update the secure files silverstripe module to SS3.
In it, the author uses the following ComplexTableField:
class SecureFileTokenPermissionDecorator extends DataExtension {
static $has_many = array(
'AccessTokens' => 'SecureFileAccessToken'
);
....
$tokenList = new ComplexTableField(
$this->owner,
'ContainedFileTokens',
'SecureFileAccessToken',
null,
null,
"File.ParentID = '{$this->owner->ID}'",
$sourceSort = null,
"JOIN File ON FileID = File.ID"
));
$tokenList->setParentIdName('FolderID');
$tokenList->setRelationAutoSetting(false);
....
}
I was wondering how I would go about representing the same data/relation with gridfField. Thanks!
Upvotes: 0
Views: 578
Reputation: 716
Looking at the secure files module source code, I would suggest the following setup:
$tokenList = $gridField = new GridField(
'AccessTokens',
'Tokens',
$this->owner->AccessTokens(),
GridFieldConfig_RelationEditor::create()
);
This works directly on the relation getter, which is a lazy loaded list (not queried until necessary), and automatically paginated. I'm not quite sure how the setParentIdName("FolderID")
fits in here, probably unnecessary. Caution: Haven't tried this on the actual codebase.
If you need some help understanding the API on a higher level, have a look in the GridField docs and the "datamodel" topic.
Thanks for helping to make modules ready for SS3! :)
Upvotes: 0