Skip to content

Commit 3360663

Browse files
[5.x] Support multiple defaults for checkboxes fieldtype (#12021)
Co-authored-by: Jason Varga <[email protected]>
1 parent dac04b9 commit 3360663

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/Fieldtypes/Checkboxes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function configFieldItems(): array
4040
'default' => [
4141
'display' => __('Default Value'),
4242
'instructions' => __('statamic::messages.fields_default_instructions'),
43-
'type' => 'text',
43+
'type' => 'taggable',
4444
],
4545
],
4646
],

src/Fieldtypes/Taggable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Statamic\Facades\GraphQL;
66
use Statamic\Fields\Fieldtype;
7+
use Statamic\Support\Arr;
78

89
class Taggable extends Fieldtype
910
{
@@ -38,7 +39,7 @@ public function preload()
3839

3940
public function preProcess($data)
4041
{
41-
return ($data) ? $data : [];
42+
return Arr::wrap($data);
4243
}
4344

4445
public function toGqlType()

tests/Fieldtypes/TaggableTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Fieldtypes;
4+
5+
use PHPUnit\Framework\Attributes\Test;
6+
use Statamic\Fields\Field;
7+
use Statamic\Fieldtypes\Taggable;
8+
use Tests\TestCase;
9+
10+
class TaggableTest extends TestCase
11+
{
12+
#[Test]
13+
public function it_pre_processes()
14+
{
15+
$this->assertEquals(['foo'], $this->field()->preProcess('foo'));
16+
$this->assertEquals(['foo'], $this->field()->preProcess(['foo']));
17+
$this->assertEquals(['foo', 'bar'], $this->field()->preProcess(['foo', 'bar']));
18+
$this->assertEquals([], $this->field()->preProcess(null));
19+
}
20+
21+
private function field($config = [])
22+
{
23+
$ft = new Taggable;
24+
25+
return $ft->setField(new Field('test', array_merge($config, ['type' => $ft->handle()])));
26+
}
27+
}

0 commit comments

Comments
 (0)