Your IP : 216.73.216.79


Current Path : /var/www/html/dynaweb-starter/plugin/dynaweb-theme/src/
Upload File :
Current File : /var/www/html/dynaweb-starter/plugin/dynaweb-theme/src/Configuration.php

<?php

namespace Dynaweb\DynawebTheme;

use Closure;
use Filament\Support\Colors\Color;
use Filament\FontProviders\GoogleFontProvider;
use Dynaweb\DynawebTheme\Repositories\ThemeSettingsRepository;
use Dynaweb\DynawebTheme\Models\ThemeSettings;
use Filament\Panel;
use Illuminate\Support\Facades\Storage;

trait Configuration
{
    private function getStoragePath($path)
    {
        return Url('') . "/storage/" . $path;
    }

    public function loadThemeSetting($panel)
    {

        $theme_settings =  json_decode(Storage::disk('local')->get('theme-settings.json'));

        if(empty($theme_settings)) {
            return $this;
        }

        if(isset($theme_settings->brand_options) && $theme_settings->brand_options == 'logo') {
            $panel->brandLogo($this->getStoragePath($theme_settings->logo));
        } else {
            $panel->brandName($theme_settings->title);
        }

        if(isset($theme_settings->favicon)) {
            $panel->favicon($this->getStoragePath($theme_settings->favicon));
        }

        if(isset($theme_settings->google_font)) {
            $panel->font($theme_settings->google_font, provider: GoogleFontProvider::class);
        }

        try {

            $panel

            // ->font('AR One Sans', provider: GoogleFontProvider::class)
            ->colors([
                'danger' => isset($theme_settings?->danger_color)
                    //? constant("Filament\Support\Colors\Color::{$theme_settings->primary_color}")
                    ? Color::hex($theme_settings->danger_color)
                    : Color::Red,
                'gray'   => isset($theme_settings?->gray_color)
                    // ? constant("Filament\Support\Colors\Color::{$theme_settings->gray_color}")
                    ? Color::hex($theme_settings->gray_color)
                    : Color::Gray,
                'info'    =>  isset($theme_settings->info_color)
                    // ? constant("Filament\Support\Colors\Color::{$theme_settings->info_color}")
                    ? Color::hex($theme_settings->info_color)
                    : Color::Blue,
                'primary' => isset($theme_settings?->primary_color)
                    // ? constant("Filament\Support\Colors\Color::{$theme_settings->primary_color}")
                    ? Color::hex($theme_settings->primary_color)
                    : Color::Cyan,
                'success' => isset($theme_settings?->success_color)
                    // ? constant("Filament\Support\Colors\Color::{$theme_settings->success_color}")
                    ? Color::hex($theme_settings->success_color)
                    : Color::Green,
                'warning' => isset($theme_settings?->warning_color)
                    ? Color::hex($theme_settings->warning_color)
                    // ? constant("Filament\Support\Colors\Color::{$theme_settings->warning_color}")
                    : Color::Yellow,
            ])
            ;

        } catch (\Spatie\Color\Exceptions\InvalidColorValue $t) {
            session()->flash('message', 'Incorrect value supplied for hex color, setting to the theme color will be not applied.');
        }
        return $this;
    }
}