Skip to content
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
1 change: 1 addition & 0 deletions lang/en/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
'globals_blueprint_instructions' => 'Controls the fields to be displayed when editing the variables.',
'globals_configure_handle_instructions' => 'Used to reference this global set on the frontend. This cannot be easily changed later.',
'globals_configure_intro' => 'A global set is a group of variables available across all front-end pages.',
'globals_configure_layout_mode_instructions' => 'Choose how fields are arranged when editing this global set.',
'globals_configure_title_instructions' => 'Use a noun representing the set\'s contents, such as \'Brand\' or \'Company\'',
'impersonate_action_confirmation' => 'You will be logged in as this user. You can return to your account using the avatar menu.',
'licensing_config_cached_warning' => 'Any changes you make to your .env or config files will not be detected until you clear the cache. If you are seeing unexpected licensing results here, it may be because of this. You can use the <code>php artisan config:cache</code> command to regenerate the cache.',
Expand Down
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
4 changes: 3 additions & 1 deletion 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 All @@ -28,7 +29,7 @@ defineProps([
</script>

<template>
<div class="max-w-5xl 3xl:max-w-6xl mx-auto" data-max-width-wrapper>
<div :class="asConfig ? 'max-w-page mx-auto' : 'max-w-5xl 3xl:max-w-6xl mx-auto'" data-max-width-wrapper>
<Head :title="__('Edit Global Set')" />

<GlobalPublishForm
Expand All @@ -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
7 changes: 7 additions & 0 deletions src/Globals/GlobalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GlobalSet implements ContainsQueryableValues, Contract

protected $title;
protected $handle;
protected $layoutMode;
protected $afterSaveCallbacks = [];
protected $withEvents = true;
private $sites = [];
Expand All @@ -52,6 +53,11 @@ public function title($title = null)
->args(func_get_args());
}

public function layoutMode($mode = null)
{
return $this->fluentlyGetOrSet('layoutMode')->args(func_get_args());
}

public function blueprint()
{
return Blueprint::find('globals.'.$this->handle());
Expand Down Expand Up @@ -171,6 +177,7 @@ public function fileData()
{
return Arr::removeNullValues([
'title' => $this->title(),
'layout_mode' => $this->layoutMode === 'multi_column' ? 'multi_column' : null,
'sites' => Site::multiEnabled() ? $this->origins()->all() : null,
]);
}
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' => $set->layoutMode() === 'multi_column',
'locale' => $variables->locale(),
'localizedFields' => $variables->data()->keys()->all(),
'hasOrigin' => $hasOrigin,
Expand Down
13 changes: 12 additions & 1 deletion src/Http/Controllers/CP/Globals/GlobalsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function edit($set)
$values = [
'title' => $set->title(),
'blueprint' => optional($set->blueprint())->handle(),
'layout_mode' => $set->layoutMode(),
'sites' => Site::all()->map(function ($site) use ($set) {
return [
'name' => $site->name(),
Expand Down Expand Up @@ -100,7 +101,7 @@ public function update(Request $request, $set)

$set
->title($values['title'])
->blueprint($values['blueprint']);
->layoutMode($values['layout_mode']);

if (Site::multiEnabled()) {
$sites = collect($values['sites'])
Expand Down Expand Up @@ -183,6 +184,16 @@ protected function editFormBlueprint($set)
],
],
],
'layout_mode' => [
'display' => __('Layout Mode'),
'instructions' => __('statamic::messages.globals_configure_layout_mode_instructions'),
'type' => 'button_group',
'default' => 'default',
'options' => [
'default' => __('Default'),
'multi_column' => __('Multi-column'),
],
],
],
],
];
Expand Down
1 change: 1 addition & 0 deletions src/Stache/Stores/GlobalsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected function makeBaseGlobalFromFile($handle, $path, $data)
return GlobalSet::make()
->handle($handle)
->title($data['title'] ?? null)
->layoutMode($data['layout_mode'] ?? null)
->sites($data['sites'] ?? [])
->initialPath($path);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Data/Globals/GlobalSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,32 @@ public function it_gets_file_contents_for_saving()
$this->assertEquals($expected, $set->fileContents());
}

#[Test]
public function it_saves_layout_mode_when_using_multi_column_layout()
{
$this->setSites([
'en' => ['name' => 'English', 'locale' => 'en_US', 'url' => 'http://test.com/'],
'fr' => ['name' => 'French', 'locale' => 'fr_FR', 'url' => 'http://fr.test.com/'],
'de' => ['name' => 'German', 'locale' => 'de_DE', 'url' => 'http://test.com/de/'],
]);

$set = (new GlobalSet)->title('The title')->sites(['en' => null, 'fr' => 'en'])->layoutMode('multi_column');

$expected = <<<'EOT'
title: 'The title'
layout_mode: multi_column
sites:
en: null
fr: en

EOT;
$this->assertEquals($expected, $set->fileContents());

$set->layoutMode('default');

$this->assertStringNotContainsString('layout_mode', $set->fileContents());
}

#[Test]
public function it_saves_through_the_api()
{
Expand Down
25 changes: 25 additions & 0 deletions tests/Feature/Globals/EditGlobalVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,38 @@ 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_global_set_uses_multi_column_layout()
{
$blueprint = Blueprint::make()->setContents(['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')->layoutMode('multi_column')->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
6 changes: 5 additions & 1 deletion tests/Feature/Globals/UpdateGlobalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ public function it_updates_global_set()

$this
->actingAs($user)
->patchJson($global->updateUrl(), ['title' => 'Testing'])
->patchJson($global->updateUrl(), [
'title' => 'Testing',
'layout_mode' => 'multi_column',
])
->assertSuccessful();

$global = GlobalSet::find('test');
$this->assertEquals('Testing', $global->title());
$this->assertEquals('multi_column', $global->layoutMode());

Event::assertDispatched(GlobalSetSaved::class, function ($event) {
return $event->globals->handle() === 'test';
Expand Down
Loading