Skip to content

Commit

Permalink
Merge pull request #105 from tomstgeorge/master
Browse files Browse the repository at this point in the history
Add support for setting a default value for GridFieldAddNewMultiClasss
  • Loading branch information
nyeholt committed Sep 15, 2015
2 parents 78f59a9 + b6056fc commit 381c604
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions code/GridFieldAddNewMultiClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
private $title;

private $classes;

private $defaultClass;

/**
* @var String
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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)'));
}
Expand Down

0 comments on commit 381c604

Please sign in to comment.