Skip to content

Commit

Permalink
Add url parameter to Field::image() (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Dec 26, 2023
1 parent 2d4e13d commit b17ae0f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,15 @@ final public static function hidden(
->inputData(new FormModelInputData($formModel, $property));
}

final public static function image(array $config = [], ?string $theme = null): Image
final public static function image(?string $url = null, array $config = [], ?string $theme = null): Image
{
return Image::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);
$field = Image::widget(config: $config, theme: $theme ?? static::DEFAULT_THEME);

if ($url !== null) {
$field = $field->src($url);
}

return $field;
}

final public static function number(
Expand Down
13 changes: 13 additions & 0 deletions tests/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ public function testImage(): void
);
}

public function testImageWithUrl(): void
{
$html = Field::image('image.png')->render();

$expected = <<<HTML
<div>
<input type="image" src="image.png">
</div>
HTML;

$this->assertSame($expected, $html);
}

public function testNumber(): void
{
$result = Field::number(new TestForm(), 'age')->render();
Expand Down

0 comments on commit b17ae0f

Please sign in to comment.