Skip to content

Commit e46d0fb

Browse files
authored
Merge pull request #66 from Log1x/add-button-group
Add Button Group field. Fixes #65
2 parents 5d80396 + 46d3528 commit e46d0fb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/FieldsBuilder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,17 @@ public function addCheckbox($name, array $args = [])
371371
return $this->addChoiceField($name, 'checkbox', $args);
372372
}
373373

374+
/**
375+
* @param string $name
376+
* @param array $args field configuration
377+
* @throws FieldNameCollisionException if name already exists.
378+
* @return FieldBuilder
379+
*/
380+
public function addButtonGroup($name, array $args = [])
381+
{
382+
return $this->addChoiceField($name, 'button_group', $args);
383+
}
384+
374385
/**
375386
* @param string $name
376387
* @param array $args field configuration

tests/FieldsBuilderTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,31 @@ public function testAddCheckbox()
379379
$this->assertArraySubset($expectedConfig, $builder->build());
380380
}
381381

382+
public function testAddButtonGroup()
383+
{
384+
$builder = new FieldsBuilder('fields');
385+
$builder->addButtonGroup('colors')
386+
->addChoice('red')
387+
->addChoice('blue')
388+
->addChoice('green');
389+
390+
$expectedConfig = [
391+
'fields' => [
392+
[
393+
'name' => 'colors',
394+
'type' => 'button_group',
395+
'choices' => [
396+
'red' => 'red',
397+
'blue' => 'blue',
398+
'green' => 'green',
399+
],
400+
],
401+
],
402+
];
403+
404+
$this->assertArraySubset($expectedConfig, $builder->build());
405+
}
406+
382407
public function testAddPostObject()
383408
{
384409
$builder = new FieldsBuilder('fields');
@@ -550,7 +575,7 @@ public function testAddGoogleMap()
550575

551576
$this->assertArraySubset($expectedConfig, $builder->build());
552577
}
553-
578+
554579
public function testAddLink()
555580
{
556581
$builder = new FieldsBuilder('fields');

0 commit comments

Comments
 (0)