bratiask/silverstripe-pickerfield

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

Installs: 115

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 27

Type:silverstripe-vendormodule

5.0.0 2023-12-21 12:42 UTC

This package is not auto-updated.

Last update: 2024-11-21 16:52:58 UTC


README

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;