Skip to content

Commit

Permalink
Added returnFormat to ColorPicker field
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Nov 2, 2023
1 parent df3dbd3 commit deceea5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Fields/ColorPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Extended\ACF\Fields\Settings\Instructions;
use Extended\ACF\Fields\Settings\Required;
use Extended\ACF\Fields\Settings\Wrapper;
use InvalidArgumentException;

class ColorPicker extends Field
{
Expand All @@ -35,4 +36,19 @@ public function opacity(): static

return $this;
}

/**
* @param string $format array, string
* @throws \InvalidArgumentException
*/
public function returnFormat(string $format): static
{
if (!in_array($format, ['array', 'string'])) {
throw new InvalidArgumentException("Invalid argument return format [$format].");
}

$this->settings['return_format'] = $format;

return $this;
}
}
12 changes: 12 additions & 0 deletions tests/Fields/ColorPickerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Extended\ACF\Tests\Fields\Settings\Instructions;
use Extended\ACF\Tests\Fields\Settings\Required;
use Extended\ACF\Tests\Fields\Settings\Wrapper;
use InvalidArgumentException;

class ColorPickerTest extends FieldTestCase
{
Expand All @@ -36,4 +37,15 @@ public function testOpacity()
$field = ColorPicker::make('Opacity')->opacity()->get();
$this->assertTrue($field['enable_opacity']);
}

public function testReturnFormat()
{
$field = ColorPicker::make('Return Format')->returnFormat('array')->get();
$this->assertSame('array', $field['return_format']);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid argument return format [test].');

ColorPicker::make('Invalid Return Format')->returnFormat('test')->get();
}
}

0 comments on commit deceea5

Please sign in to comment.