Skip to content
Open
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: 2 additions & 0 deletions resources/js/components/globals/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
:name="publishContainer"
:reference="reference"
:blueprint="fieldset"
:as-config="asConfig"
v-model="values"
:meta="meta"
:origin-values="originValues"
Expand Down Expand Up @@ -148,6 +149,7 @@ export default {
canConfigure: Boolean,
configureUrl: String,
canEditBlueprint: Boolean,
asConfig: Boolean,
},

data() {
Expand Down
2 changes: 2 additions & 0 deletions resources/js/pages/globals/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defineProps([
'reference',
'blueprintHandle',
'blueprint',
'asConfig',
'values',
'localizedFields',
'meta',
Expand Down Expand Up @@ -41,6 +42,7 @@ defineProps([
:initial-reference="reference"
:initial-blueprint-handle="blueprintHandle"
:initial-fieldset="blueprint"
:as-config="asConfig"
:initial-values="values"
:initial-localized-fields="localizedFields"
:initial-meta="meta"
Expand Down
6 changes: 4 additions & 2 deletions src/CP/PublishForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ public function toResponse($request)
->addValues($this->values)
->preProcess();

$asConfig = $this->asConfig || $this->blueprint->asConfig();

$viewData = [
'blueprint' => $this->blueprint->toPublishArray(),
'icon' => $this->icon ?? ($this->asConfig ? 'cog' : null),
'icon' => $this->icon ?? ($asConfig ? 'cog' : null),
'title' => $this->title,
'values' => $fields->values(),
'meta' => $fields->meta(),
'readOnly' => $this->readOnly,
'submitUrl' => $this->submitUrl,
'submitMethod' => $this->submitMethod,
'asConfig' => $this->asConfig,
'asConfig' => $asConfig,
];

if ($request->wantsJson()) {
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ public function title()
return Arr::get($this->contents, 'title', Str::humanize(Str::of($this->handle)->after('::')->afterLast('.')));
}

public function asConfig(): bool
{
return Arr::get($this->contents, 'as_config', false);
}

public function isNamespaced(): bool
{
return Facades\Blueprint::getAdditionalNamespaces()->has($this->namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function edit(Request $request, $id)
'values' => $values,
'meta' => $meta,
'blueprint' => $blueprint->toPublishArray(),
'asConfig' => $blueprint->asConfig(),
'locale' => $variables->locale(),
'localizedFields' => $variables->data()->keys()->all(),
'hasOrigin' => $hasOrigin,
Expand Down
28 changes: 28 additions & 0 deletions tests/Feature/Globals/EditGlobalVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,41 @@ public function it_shows_the_form()
->assertSuccessful()
->assertInertia(fn (Assert $page) => $page
->component('globals/Edit')
->where('asConfig', false)
->has('values', fn (Assert $page) => $page
->where('foo', 'bar')
->where('unused', null)
)
);
}

#[Test]
public function it_passes_as_config_when_the_blueprint_opts_in()
{
$blueprint = Blueprint::make()->setContents([
'as_config' => true,
'fields' => [
['handle' => 'foo', 'field' => ['type' => 'text']],
],
]);
Blueprint::partialMock();
Blueprint::shouldReceive('find')->with('globals.test')->andReturn($blueprint);
$this->setTestRoles(['test' => ['access cp', 'edit test globals']]);
$user = User::make()->assignRole('test')->save();

$global = GlobalSet::make('test')->save();
$global->in('en')->data(['foo' => 'bar'])->save();

$this
->actingAs($user)
->get($global->in('en')->editUrl())
->assertSuccessful()
->assertInertia(fn (Assert $page) => $page
->component('globals/Edit')
->where('asConfig', true)
);
}

#[Test]
public function it_shows_the_form_even_if_localization_does_not_exist()
{
Expand Down
8 changes: 8 additions & 0 deletions tests/Fields/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public function it_gets_the_title()
$this->assertEquals('Test', $blueprint->title());
}

#[Test]
public function it_gets_the_as_config_property_which_is_false_by_default()
{
$this->assertFalse((new Blueprint)->asConfig());
$this->assertFalse((new Blueprint)->setContents(['as_config' => false])->asConfig());
$this->assertTrue((new Blueprint)->setContents(['as_config' => true])->asConfig());
}

#[Test]
public function it_gets_the_hidden_property_which_is_false_by_default()
{
Expand Down
Loading