From b6056fc7b9bbeccbab8441e9271f5ae5c09d3faf Mon Sep 17 00:00:00 2001 From: tsg Date: Mon, 14 Sep 2015 18:16:36 -0500 Subject: [PATCH] add support for setting a default value for GridFieldAddNewMultiClasss --- code/GridFieldAddNewMultiClass.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/code/GridFieldAddNewMultiClass.php b/code/GridFieldAddNewMultiClass.php index e5075d88..9d4d1eaa 100755 --- a/code/GridFieldAddNewMultiClass.php +++ b/code/GridFieldAddNewMultiClass.php @@ -19,6 +19,8 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL private $title; private $classes; + + private $defaultClass; /** * @var String @@ -112,11 +114,23 @@ public function getClasses(GridField $grid) { * @param array $classes a set of class names, optionally mapped to titles * @return GridFieldAddNewMultiClass $this */ - public function setClasses(array $classes) { + public function setClasses(array $classes, $default = null) { $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; + } + /** * Handles adding a new instance of a selected class. * @@ -157,7 +171,7 @@ public function getHTMLFragments($grid) { 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')) { $field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)')); }