Merge pull request #9743 from kinglozzer/treedropdown-root-id

NEW: Expose TreeDropdownField root node ID in schema
This commit is contained in:
Maxime Rainville 2021-04-23 18:06:23 +12:00 committed by GitHub
commit 67a008365a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -901,6 +901,7 @@ class TreeDropdownField extends FormField
$data['data'] = array_merge($data['data'], [ $data['data'] = array_merge($data['data'], [
'urlTree' => $this->Link('tree'), 'urlTree' => $this->Link('tree'),
'showSearch' => $this->getShowSearch(), 'showSearch' => $this->getShowSearch(),
'treeBaseId' => $this->getTreeBaseID(),
'emptyString' => $this->getEmptyString(), 'emptyString' => $this->getEmptyString(),
'hasEmptyDefault' => $this->getHasEmptyDefault(), 'hasEmptyDefault' => $this->getHasEmptyDefault(),
'multiple' => false, 'multiple' => false,

View File

@ -8,6 +8,8 @@ use SilverStripe\Control\Session;
use SilverStripe\Dev\CSSContentParser; use SilverStripe\Dev\CSSContentParser;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\TreeDropdownField; use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\ORM\Tests\HierarchyTest\TestObject; use SilverStripe\ORM\Tests\HierarchyTest\TestObject;
@ -246,4 +248,33 @@ class TreeDropdownFieldTest extends SapphireTest
$result $result
); );
} }
public function testTreeBaseID()
{
$treeBaseID = $this->idFromFixture(Folder::class, 'folder1');
$field = new TreeDropdownField('TestTree', 'Test tree', Folder::class);
// getSchemaDataDefaults needs the field to be attach to a form
new Form(
null,
'mock',
new FieldList($field)
);
$this->assertEmpty($field->getTreeBaseID(), 'TreeBaseId does not have an initial value');
$field->setTreeBaseID($treeBaseID);
$this->assertEquals(
$treeBaseID,
$field->getTreeBaseID(),
'Value passed to setTreeBaseID is returned by getTreeBaseID'
);
$schema = $field->getSchemaDataDefaults();
$this->assertEquals(
$treeBaseID,
$schema['data']['treeBaseId'],
'TreeBaseId is included in the default schema data'
);
}
} }