Skip to content

Commit

Permalink
fix(has-block-type): add call with single block type
Browse files Browse the repository at this point in the history
  • Loading branch information
evolkmann committed Sep 30, 2024
1 parent bf9fed8 commit f651f91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/LayoutHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

class LayoutHelpers {

static function hasBlockType(Layout $layout, array $blockTypes): bool
static function hasBlockType(Layout $layout, array|string $blockTypes): bool
{
$blockTypesArray = is_array($blockTypes) ? $blockTypes : [$blockTypes];
foreach ($layout->columns() as $column) {
foreach ($column->blocks() as $block) {
if (in_array($block->type(), $blockTypes)) {
if (in_array($block->type(), $blockTypesArray)) {
return true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/LayoutHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function testHasBlockType(): void
]
]);

$this->assertTrue(LayoutHelpers::hasBlockType($layout, 'heading'));
$this->assertTrue(LayoutHelpers::hasBlockType($layout, ['heading']));
$this->assertFalse(LayoutHelpers::hasBlockType($layout, 'image'));
$this->assertFalse(LayoutHelpers::hasBlockType($layout, ['image']));
}

Expand Down

0 comments on commit f651f91

Please sign in to comment.