From dc1a16be4c8a3bf245bc9520fdd2c74de67f9817 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 17 Feb 2018 12:36:24 +0000 Subject: [PATCH] Made it possible to override icons via custom theme --- app/helpers.php | 31 ++++++++++++++++++++++++++++++- config/view.php | 13 +++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/helpers.php b/app/helpers.php index daa747e71..c087e3509 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -130,13 +130,42 @@ function redirect($to = null, $status = 302, $headers = [], $secure = null) return app('redirect')->to($to, $status, $headers, $secure); } +/** + * Get a path to a theme resource. + * @param string $path + * @return string|boolean + */ +function theme_path($path = '') +{ + $theme = config('view.theme'); + if (!$theme) { + return false; + } + + return base_path('themes/' . $theme .($path ? DIRECTORY_SEPARATOR.$path : $path)); +} + +/** + * Get fetch an SVG icon as a string. + * Checks for icons defined within a custom theme before defaulting back + * to the 'resources/assets/icons' folder. + * @param $name + * @param array $attrs + * @return mixed + */ function icon($name, $attrs = []) { - $iconPath = resource_path('assets/icons/' . $name . '.svg'); $attrString = ' '; foreach ($attrs as $attrName => $attr) { $attrString .= $attrName . '="' . $attr . '" '; } + + $iconPath = resource_path('assets/icons/' . $name . '.svg'); + $themeIconPath = theme_path('icons/' . $name . '.svg'); + if ($themeIconPath && file_exists($themeIconPath)) { + $iconPath = $themeIconPath; + } + $fileContents = file_get_contents($iconPath); return str_replace('` folder to hold the + | custom theme overrides. + | + */ + + 'theme' => env('APP_THEME', false), + /* |-------------------------------------------------------------------------- | View Storage Paths