Skip to content

Commit

Permalink
working support for old style block factories
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Feb 18, 2024
1 parent 1df9535 commit aeb0bf3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/factories/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function resolveFactories(array $values, FieldInterface $field)
// will go in to the model okay, but when you try to pull them back out to save them
// you get an EntryQuery with no access to the raw array of unsaved entries.
// Because of that we call ->create() here on all nested factories.
$values[$index] = $field instanceof Matrix ? collection_wrap($value->make())->map(function (\craft\elements\Entry $entry) {
return [
$values[$index] = $field instanceof Matrix ? collection_wrap($value->make())->map(function (\craft\elements\Entry|array $entry) {
return is_array($entry) ? $entry : [
'type' => $entry->getType()->handle,
'enabled' => true,
'collapsed' => false,
Expand Down
12 changes: 12 additions & 0 deletions tests/FactoryMatrixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
expect($entry->matrixField->all())->toHaveCount(2);
});

it('can use old Block factories', function () {
$entry = EntryFactory::factory()
->section('posts')
->matrixField(
BlockFactory::factory()->type('blockTypeOne')->fieldOne('foo'),
BlockFactory::factory()->type('blockTypeOne')->fieldOne('bar'),
)
->create();

expect($entry->matrixField->all())->toHaveCount(2);
});

it('can fill matrix fields with multiple blocks', function () {
$entry = EntryFactory::factory()
->section('posts')
Expand Down

0 comments on commit aeb0bf3

Please sign in to comment.