Skip to content

SilverStripe 3 GridField based management of has_one , has_many , and many_many relationship selection

Notifications You must be signed in to change notification settings

briceburg/silverstripe-pickerfield

Repository files navigation

silverstripe-pickerfield

SilverStripe 3 GridField based management of has_one , has_many , and many_many relationship selection

Requirements

Why?

  1. An efficient* GridField based interface to manage relationship selections.
  2. GridField doesn't appear to natively support has_one relationships.
  3. The ability to edit and create selected items.

Thanks to the great work of the SilverStripe team and Andrew Short's GridFieldExtensions, the development of this module was a bit easier. Be kind to them.

* by efficient we needed ajax + pagination, as we couldn't load all records into a dropdown list for instance.

Usage Overview

Screenshots; ###overview overview ###link button search [via GridFieldExtensions] link button search [via GridFieldExtensions]

/***********************
	Mock DataObject
************************/

class Dog extends DataObject {
	static $db = array(
		'Title'				=> 'Varchar',
		// ....
	);
	
	static $has_one = array(
		'Breeder'			=> 'Breeder'
		'Dam'				=> 'Dog',
		'Sire'				=> 'Dog',
		// ....
	);
	
	static $has_many = array(
		'Owners'	=> 'Member',
		// ....
	);
	
// ....

}


/***********************
	Field Usage
************************/

// sortable field appropriate for selection of has_many and many_many objects
$field = new PickerField('Owners', 'Owners', $this->Owners(), 'Select Owner(s)', 'SortOrder');

// non-sortable version of the above
$field = new PickerField('Owners', 'Owners', $this->Owners());

// sortable field appropriate for the parent selection of a has_one relationship
$field = new HasOnePickerField($this, 'DamID', 'Selected Dam', $this->Dam(), 'Select a Dam');


// we also allow the ability to create and edit associated records via enableCreate, enableEdit methods.
$fields->addFieldsToTab('Root.Main', array(
  new HeaderField('Info','Info Blocks'),
  $field = new HasOnePickerField($this, 'AboutInfoBlockID', 'About Block', $this->AboutInfoBlock())
));
        
$field->enableCreate('Add Block')->enableEdit();
 

Bugs

For support or questions, please use the GitHub provided issue tracker;

About

SilverStripe 3 GridField based management of has_one , has_many , and many_many relationship selection

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages