Merge branch '4.1' into 4

This commit is contained in:
Robbie Averill 2018-04-10 16:27:00 +12:00
commit af2c3886b9
3 changed files with 50 additions and 13 deletions

View File

@ -223,19 +223,30 @@ abstract class BulkLoader extends ViewableData
**/ **/
public function getImportSpec() public function getImportSpec()
{ {
$spec = array(); $singleton = DataObject::singleton($this->objectClass);
// get database columns (fieldlabels include fieldname as a key) // get database columns (fieldlabels include fieldname as a key)
// using $$includerelations flag as false, so that it only contain $db fields // using $$includerelations flag as false, so that it only contain $db fields
$spec['fields'] = (array)singleton($this->objectClass)->fieldLabels(false); $fields = (array)$singleton->fieldLabels(false);
$has_ones = singleton($this->objectClass)->hasOne(); // Merge relations
$has_manys = singleton($this->objectClass)->hasMany(); $relations = array_merge(
$many_manys = singleton($this->objectClass)->manyMany(); $singleton->hasOne(),
$singleton->hasMany(),
$singleton->manyMany()
);
$spec['relations'] = (array)$has_ones + (array)$has_manys + (array)$many_manys; // Ensure description is string (e.g. many_many through)
foreach ($relations as $name => $desc) {
if (!is_string($desc)) {
$relations[$name] = $name;
}
}
return $spec; return [
'fields' => $fields,
'relations' => $relations,
];
} }
/** /**

View File

@ -2,7 +2,7 @@
<ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>"> <ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>">
<% loop $FieldSet %> <% loop $FieldSet %>
<% if $Selected %> <% if $Selected %>
<li$Selected> <li class="selected">
$RadioLabel $RadioLabel
$FieldHolder $FieldHolder
</li> </li>
@ -12,7 +12,7 @@
<% else %> <% else %>
<ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>"> <ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>">
<% loop $FieldSet %> <% loop $FieldSet %>
<li$Selected> <li <% if Selected %>class="selected"<% end_if %>>
<label>{$RadioButton} {$RadioLabel}</label> <label>{$RadioButton} {$RadioLabel}</label>
<% if $FieldList %> <% if $FieldList %>
$FieldHolder $FieldHolder

View File

@ -10,8 +10,7 @@ use SilverStripe\Forms\SelectionGroup;
class SelectionGroupTest extends SapphireTest class SelectionGroupTest extends SapphireTest
{ {
public function testFieldHolder()
function testFieldHolder()
{ {
$items = array( $items = array(
new SelectionGroup_Item( new SelectionGroup_Item(
@ -41,7 +40,34 @@ class SelectionGroupTest extends SapphireTest
$this->assertContains('two view', (string)$listElTwo->div); $this->assertContains('two view', (string)$listElTwo->div);
} }
function testLegacyItemsFieldHolder() public function testSelectedFieldHolder()
{
$items = array(
new SelectionGroup_Item(
'one',
new LiteralField('one', 'one view'),
'one title'
),
new SelectionGroup_Item(
'two',
new LiteralField('two', 'two view'),
'two title'
),
);
$field = new SelectionGroup('MyGroup', $items);
$field->setValue('two');
$parser = new CSSContentParser($field->FieldHolder());
$listEls = $parser->getBySelector('li');
$listElOne = $listEls[0];
$listElTwo = $listEls[1];
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
$this->assertEquals('selected', (string)$listElTwo->attributes()->class);
}
public function testLegacyItemsFieldHolder()
{ {
$items = array( $items = array(
'one' => new LiteralField('one', 'one view'), 'one' => new LiteralField('one', 'one view'),
@ -60,7 +86,7 @@ class SelectionGroupTest extends SapphireTest
$this->assertEquals(' two', (string)$listElTwo->label[0]); $this->assertEquals(' two', (string)$listElTwo->label[0]);
} }
function testLegacyItemsFieldHolderWithTitle() public function testLegacyItemsFieldHolderWithTitle()
{ {
$items = array( $items = array(
'one//one title' => new LiteralField('one', 'one view'), 'one//one title' => new LiteralField('one', 'one view'),