diff --git a/resources/js/components/globals/PublishForm.vue b/resources/js/components/globals/PublishForm.vue index 25ecc980980..cf740a8b6fc 100644 --- a/resources/js/components/globals/PublishForm.vue +++ b/resources/js/components/globals/PublishForm.vue @@ -74,6 +74,7 @@ :name="publishContainer" :reference="reference" :blueprint="fieldset" + :as-config="asConfig" v-model="values" :meta="meta" :origin-values="originValues" @@ -148,6 +149,7 @@ export default { canConfigure: Boolean, configureUrl: String, canEditBlueprint: Boolean, + asConfig: Boolean, }, data() { diff --git a/resources/js/pages/globals/Edit.vue b/resources/js/pages/globals/Edit.vue index ec09a6d5e07..343a7cf9803 100644 --- a/resources/js/pages/globals/Edit.vue +++ b/resources/js/pages/globals/Edit.vue @@ -10,6 +10,7 @@ defineProps([ 'reference', 'blueprintHandle', 'blueprint', + 'asConfig', 'values', 'localizedFields', 'meta', @@ -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" diff --git a/src/CP/PublishForm.php b/src/CP/PublishForm.php index fe3610e68eb..7de18feb2c6 100644 --- a/src/CP/PublishForm.php +++ b/src/CP/PublishForm.php @@ -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()) { diff --git a/src/Fields/Blueprint.php b/src/Fields/Blueprint.php index 33619eb35f3..c0b1a645475 100644 --- a/src/Fields/Blueprint.php +++ b/src/Fields/Blueprint.php @@ -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); diff --git a/src/Http/Controllers/CP/Globals/GlobalVariablesController.php b/src/Http/Controllers/CP/Globals/GlobalVariablesController.php index 6f4d9ce7200..c6f553c4481 100644 --- a/src/Http/Controllers/CP/Globals/GlobalVariablesController.php +++ b/src/Http/Controllers/CP/Globals/GlobalVariablesController.php @@ -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, diff --git a/tests/Feature/Globals/EditGlobalVariablesTest.php b/tests/Feature/Globals/EditGlobalVariablesTest.php index 0a52b216f65..7db14bb41df 100644 --- a/tests/Feature/Globals/EditGlobalVariablesTest.php +++ b/tests/Feature/Globals/EditGlobalVariablesTest.php @@ -52,6 +52,7 @@ 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) @@ -59,6 +60,33 @@ public function it_shows_the_form() ); } + #[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() { diff --git a/tests/Fields/BlueprintTest.php b/tests/Fields/BlueprintTest.php index e9e4232f41c..6fbe4bcf54b 100644 --- a/tests/Fields/BlueprintTest.php +++ b/tests/Fields/BlueprintTest.php @@ -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() {