Skip to content

Commit

Permalink
[5.x] Support strings in bard_text & bard_html modifiers (#10369)
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell authored Jun 27, 2024
1 parent d2cc216 commit a53391d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Modifiers/CoreModifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ public function bardText($value)
return '';
}

if (is_string($value)) {
return strip_tags($value);
}

if (Arr::isAssoc($value)) {
$value = [$value];
}
Expand All @@ -296,6 +300,11 @@ public function bardHtml($value)
if ($value instanceof Value) {
$value = $value->raw();
}

if (is_string($value)) {
return $value;
}

if (Arr::isAssoc($value)) {
$value = [$value];
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Modifiers/BardHtmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public function it_extracts_bard_html_from_value_object()
$this->assertEquals($expected, $this->modify($data));
}

#[Test]
public function it_returns_string()
{
$data = '<p>This is a paragraph.</p>';

$expected = '<p>This is a paragraph.</p>';

$this->assertEquals($expected, $this->modify($data));
}

public function modify($arr, ...$args)
{
return Modify::value($arr)->bard_html($args)->fetch();
Expand Down
10 changes: 10 additions & 0 deletions tests/Modifiers/BardTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ public function it_extracts_bard_text_from_value_object()
$this->assertEquals($expected, $this->modify($data));
}

#[Test]
public function it_extracts_bard_text_from_string()
{
$data = 'This <b>is a</b> paragraph.';

$expected = 'This is a paragraph.';

$this->assertEquals($expected, $this->modify($data));
}

#[Test]
public function it_handles_null()
{
Expand Down

0 comments on commit a53391d

Please sign in to comment.