mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Merge pull request #105 from tomstgeorge/master
Add support for setting a default value for GridFieldAddNewMultiClasss
This commit is contained in:
commit
381c6044ee
@ -20,6 +20,8 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
|||||||
|
|
||||||
private $classes;
|
private $classes;
|
||||||
|
|
||||||
|
private $defaultClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var String
|
* @var String
|
||||||
*/
|
*/
|
||||||
@ -112,8 +114,20 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
|||||||
* @param array $classes a set of class names, optionally mapped to titles
|
* @param array $classes a set of class names, optionally mapped to titles
|
||||||
* @return GridFieldAddNewMultiClass $this
|
* @return GridFieldAddNewMultiClass $this
|
||||||
*/
|
*/
|
||||||
public function setClasses(array $classes) {
|
public function setClasses(array $classes, $default = null) {
|
||||||
$this->classes = $classes;
|
$this->classes = $classes;
|
||||||
|
if($default) $this->defaultClass = $default;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the default class that is selected automatically.
|
||||||
|
*
|
||||||
|
* @param string $default the class name to use as default
|
||||||
|
* @return GridFieldAddNewMultiClass $this
|
||||||
|
*/
|
||||||
|
public function setDefaultClass($default) {
|
||||||
|
$this->defaultClass = $default;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +171,7 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
|||||||
|
|
||||||
GridFieldExtensions::include_requirements();
|
GridFieldExtensions::include_requirements();
|
||||||
|
|
||||||
$field = new DropdownField(sprintf('%s[ClassName]', __CLASS__), '', $classes);
|
$field = new DropdownField(sprintf('%s[ClassName]', __CLASS__), '', $classes, $this->defaultClass);
|
||||||
if (Config::inst()->get('GridFieldAddNewMultiClass', 'showEmptyString')) {
|
if (Config::inst()->get('GridFieldAddNewMultiClass', 'showEmptyString')) {
|
||||||
$field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)'));
|
$field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)'));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user