Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix linking to addon fields #10324

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fields/FieldTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function toVue($field): array

private static function referenceFieldToVue($field): array
{
$fieldsetField = Arr::get(static::fieldsetFields(), $field['field'], []);
$fieldsetField = static::fieldsetFields()[$field['field']] ?? [];

$mergedConfig = array_merge(
$fieldsetFieldConfig = Arr::get($fieldsetField, 'config', []),
Expand Down
25 changes: 25 additions & 0 deletions tests/Fields/FieldTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Fields;

use Statamic\Facades\AssetContainer;
use Statamic\Fields\Fieldset;
use Statamic\Fields\FieldTransformer;
use Statamic\Fields\Fieldtype;
use Tests\PreventSavingStacheItemsToDisk;
Expand Down Expand Up @@ -366,4 +367,28 @@ public function it_saves_a_toggle_as_false_where_the_default_is_true()
'duplicate' => false,
], $fromVue['field']);
}

/** @test */
public function it_supports_addon_linked_fields()
{
$fieldset = tap(new Fieldset)
->setHandle('addon::some_fieldset')
->setContents(['fields' => [
[
'handle' => 'field1',
'field' => ['type' => 'text', 'foo' => 'bar'],
],
]]);

\Statamic\Facades\Fieldset::shouldReceive('all')->andReturn(collect([
'addon::some' => $fieldset,
]));

$this->assertEquals([
'type' => 'text',
'foo' => 'bar',
'width' => 100,
'localizable' => false,
], $this->configToVue('addon::some_fieldset.field1'));
}
}
Loading