Skip to content

Commit

Permalink
No longer misinterpret builder blocks as layouts #2966
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Dec 10, 2020
1 parent 660085d commit 05404af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Cms/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ protected static function extractFromLayouts(array $input): array
return [];
}

if (
// no columns = no layout
array_key_exists('columns', $input[0]) === false ||
// checks if this is a block for the builder plugin
array_key_exists('_key', $input[0]) === true
) {
return $input;
}

This comment has been minimized.

Copy link
@afbora

afbora Dec 10, 2020

Member

Why do we repeat the same check below when using the OR operator?

This comment has been minimized.

Copy link
@bastianallgeier

bastianallgeier Dec 10, 2020

Author Member

Argh, I'm seriously overworked. I missed to remove it. I will take care of it right now.

// no layouts
if (array_key_exists('columns', $input[0]) === false) {
return $input;
Expand Down
20 changes: 20 additions & 0 deletions tests/Cms/Blocks/BlocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ public function testFactoryFromLayouts()
$this->assertSame('text', $blocks->last()->type());
}

public function testFactoryFromBuilderWithColumns()
{
$builder = [
[
'_key' => 'heading',
'columns' => 1,
],
[
'_key' => 'text',
'columns' => 2,
]
];

$blocks = Blocks::factory($builder);

$this->assertCount(2, $blocks);
$this->assertSame('heading', $blocks->first()->type());
$this->assertSame('text', $blocks->last()->type());
}

public function testParseJson()
{
$input = [
Expand Down

0 comments on commit 05404af

Please sign in to comment.