Skip to content

Commit

Permalink
[5.x] Add new 'Settings' CP Nav section (#9857)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite authored Apr 11, 2024
1 parent 32300df commit 966782f
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 70 deletions.
1 change: 1 addition & 0 deletions resources/svg/icons/light/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions resources/views/partials/global-header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@
</a>
@endif

<dropdown-list v-cloak>
<template v-slot:trigger>
<button class="hidden md:block h-6 w-6 rtl:mr-4 ltr:ml-4 p-1 text-gray hover:text-gray-800" v-tooltip="__('Preferences')" aria-label="{{ __('Manage Preferences') }}">
@cp_svg('icons/light/cog')
</button>
</template>
<dropdown-item :text="__('Preferences')" redirect="{{ route('statamic.cp.preferences.index') }}"></dropdown-item>
<dropdown-item :text="__('CP Nav')" redirect="{{ route('statamic.cp.preferences.nav.index') }}"></dropdown-item>
</dropdown-list>

<dropdown-list v-cloak>
<template v-slot:trigger>
<button class="hidden md:block h-6 w-6 rtl:mr-4 ltr:ml-4 p-1 text-gray hover:text-gray-800" v-tooltip="__('Useful Links')" aria-label="{{ __('View Useful Links') }}">
Expand Down
29 changes: 15 additions & 14 deletions routes/cp.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,21 @@
Route::post('js', [PreferenceController::class, 'store'])->name('store');
Route::delete('js/{key}', [PreferenceController::class, 'destroy'])->name('destroy');

Route::group(['prefix' => 'nav', 'as' => 'nav.'], function () {
Route::get('/', [NavController::class, 'index'])->name('index');
Route::get('edit', [UserNavController::class, 'edit'])->name('user.edit');
Route::patch('/', [UserNavController::class, 'update'])->name('user.update');
Route::delete('/', [UserNavController::class, 'destroy'])->name('user.destroy');

Route::middleware([RequireStatamicPro::class, 'can:manage preferences'])->group(function () {
Route::get('roles/{role}/edit', [RoleNavController::class, 'edit'])->name('role.edit');
Route::patch('roles/{role}', [RoleNavController::class, 'update'])->name('role.update');
Route::delete('roles/{role}', [RoleNavController::class, 'destroy'])->name('role.destroy');
Route::get('default/edit', [DefaultNavController::class, 'edit'])->name('default.edit');
Route::patch('default', [DefaultNavController::class, 'update'])->name('default.update');
Route::delete('default', [DefaultNavController::class, 'destroy'])->name('default.destroy');
});
});

Route::group(['prefix' => 'nav', 'as' => 'preferences.nav.'], function () {
Route::get('/', [NavController::class, 'index'])->name('index');
Route::get('edit', [UserNavController::class, 'edit'])->name('user.edit');
Route::patch('/', [UserNavController::class, 'update'])->name('user.update');
Route::delete('/', [UserNavController::class, 'destroy'])->name('user.destroy');

Route::middleware([RequireStatamicPro::class, 'can:manage preferences'])->group(function () {
Route::get('roles/{role}/edit', [RoleNavController::class, 'edit'])->name('role.edit');
Route::patch('roles/{role}', [RoleNavController::class, 'update'])->name('role.update');
Route::delete('roles/{role}', [RoleNavController::class, 'destroy'])->name('role.destroy');
Route::get('default/edit', [DefaultNavController::class, 'edit'])->name('default.edit');
Route::patch('default', [DefaultNavController::class, 'update'])->name('default.update');
Route::delete('default', [DefaultNavController::class, 'destroy'])->name('default.destroy');
});
});

Expand Down
38 changes: 31 additions & 7 deletions src/CP/Navigation/CoreNav.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static function make()
->makeContentSection()
->makeFieldsSection()
->makeToolsSection()
->makeSettingsSection()
->makeUsersSection();
}

Expand Down Expand Up @@ -147,11 +148,6 @@ protected function makeContentSection()
})->filter();
});

Nav::content(Site::multiEnabled() ? 'Sites' : 'Site')
->route('sites.edit')
->icon('/sites')
->can('configure sites');

return $this;
}

Expand Down Expand Up @@ -213,7 +209,7 @@ protected function makeToolsSection()
->can('resolve duplicate ids');
}

$this->makeUtilitiesSection();
$this->makeUtilitiesItems();

if (config('statamic.graphql.enabled') && Statamic::pro()) {
Nav::tools('GraphQL')
Expand All @@ -226,7 +222,12 @@ protected function makeToolsSection()
return $this;
}

protected function makeUtilitiesSection()
/**
* Make utilities items.
*
* @return $this
*/
protected function makeUtilitiesItems()
{
$utilities = Utility::authorized()->sortBy->navTitle()->map(function ($utility) {
return Nav::item($utility->navTitle())->url($utility->url());
Expand All @@ -242,6 +243,29 @@ protected function makeUtilitiesSection()
return $this;
}

/**
* Make settings section items.
*
* @return $this
*/
protected function makeSettingsSection()
{
Nav::settings(Site::multiEnabled() ? 'Sites' : 'Site')
->route('sites.edit')
->icon('/sites')
->can('configure sites');

Nav::settings('Preferences')
->route('preferences.index')
->icon('/settings')
->children([
Nav::item('General')->route('preferences.index'),
Nav::item('CP Nav')->route('preferences.nav.index'),
]);

return $this;
}

/**
* Make users section items.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/SiteNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct($siteHandle)
public function getSolution(): Solution
{
return BaseSolution::create("The [{$this->siteHandle}] site was not found.")
->setSolutionDescription('Check the spelling of the site handle in your [content/sites.yaml].')
->setSolutionDescription('Check the spelling of the site handle in your [resources/sites.yaml].')
->setDocumentationLinks([
'Read the multi-site guide' => Statamic::docsUrl('/multi-site#configuration'),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Sites/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function setSiteValue(string $site, string $key, $value): self

public function path(): string
{
return base_path('content/sites.yaml');
return resource_path('sites.yaml');
}

protected function getSavedSites()
Expand Down
4 changes: 2 additions & 2 deletions src/UpdateScripts/MigrateSitesConfigToYaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function shouldUpdate($newVersion, $oldVersion)
public function update()
{
// Skip if already migrated
if (File::exists(base_path('content/sites.yaml'))) {
if (File::exists(resource_path('sites.yaml'))) {
return;
}

Expand All @@ -39,7 +39,7 @@ public function update()
->ensureMultisiteConfigEnabled($sites)
->removeOldSitesConfigFile();

$this->console->info('Successfully migrated [config/statamic/sites.php] to [content/sites.yaml]!');
$this->console->info('Successfully migrated [config/statamic/sites.php] to [resources/sites.yaml]!');
}

private function migrateSites($path)
Expand Down
8 changes: 5 additions & 3 deletions tests/CP/Navigation/CoreNavTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public function it_can_build_a_default_nav()
{
$expected = collect([
'Top Level' => ['Dashboard', 'Playground'],
'Content' => ['Collections', 'Navigation', 'Taxonomies', 'Assets', 'Globals', 'Site'],
'Content' => ['Collections', 'Navigation', 'Taxonomies', 'Assets', 'Globals'],
'Fields' => ['Blueprints', 'Fieldsets'],
'Tools' => ['Forms', 'Updates', 'Addons', 'Utilities', 'GraphQL'],
'Settings' => ['Site', 'Preferences'],
'Users' => ['Users', 'Groups', 'Permissions'],
]);

Expand All @@ -35,6 +36,7 @@ public function it_can_build_a_default_nav()
$this->assertEquals($expected->get('Content'), $nav->get('Content')->map->display()->all());
$this->assertEquals($expected->get('Fields'), $nav->get('Fields')->map->display()->all());
$this->assertEquals($expected->get('Tools'), $nav->get('Tools')->map->display()->all());
$this->assertEquals($expected->get('Settings'), $nav->get('Settings')->map->display()->all());
$this->assertEquals($expected->get('Users'), $nav->get('Users')->map->display()->all());
}

Expand All @@ -48,8 +50,8 @@ public function it_builds_plural_sites_item_when_multisite_is_enabled()
$nav = $this->build();

$this->assertEquals(
['Collections', 'Navigation', 'Taxonomies', 'Assets', 'Globals', 'Sites'],
$nav->get('Content')->map->display()->all()
['Sites', 'Preferences'],
$nav->get('Settings')->map->display()->all()
);
}

Expand Down
Loading

0 comments on commit 966782f

Please sign in to comment.