mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 10:39:27 +01:00
add warning when trying to enable multiple themes
This commit is contained in:
parent
aa2dfc1c5d
commit
2384cc870a
@ -20,6 +20,7 @@ use Filament\Panel;
|
||||
* @method static void enablePlugin(string|Plugin $plugin)
|
||||
* @method static void disablePlugin(string|Plugin $plugin)
|
||||
* @method static void updateLoadOrder(array<int, string> $order)
|
||||
* @method static bool hasThemePluginEnabled()
|
||||
*
|
||||
* @see \App\Services\Helpers\PluginService
|
||||
*/
|
||||
|
||||
@ -104,6 +104,9 @@ class PluginResource extends Resource
|
||||
->icon('tabler-check')
|
||||
->color('success')
|
||||
->visible(fn (Plugin $plugin) => $plugin->canEnable())
|
||||
->requiresConfirmation(fn (Plugin $plugin) => $plugin->isTheme() && Plugins::hasThemePluginEnabled())
|
||||
->modalHeading('Theme already enabled')
|
||||
->modalDescription('You already have a theme enabled. Enabling multiple themes can result in visual bugs. Do you want to continue?')
|
||||
->action(function (Plugin $plugin) {
|
||||
Plugins::enablePlugin($plugin);
|
||||
|
||||
|
||||
@ -243,6 +243,11 @@ class Plugin extends Model implements HasPluginSettings
|
||||
return !str($this->panel_version)->startsWith('^');
|
||||
}
|
||||
|
||||
public function isTheme(): bool
|
||||
{
|
||||
return $this->category === 'theme';
|
||||
}
|
||||
|
||||
/** @return null|array<string, array{version: string, download_url: string}> */
|
||||
private function getUpdateData(): ?array
|
||||
{
|
||||
|
||||
@ -297,4 +297,16 @@ class PluginService
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function hasThemePluginEnabled(): bool
|
||||
{
|
||||
$plugins = Plugin::query()->orderBy('load_order')->get();
|
||||
foreach ($plugins as $plugin) {
|
||||
if ($plugin->isTheme() && $plugin->isEnabled()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user