From 60e57a5df6870d25da7c6ca249d02c8714d34ad8 Mon Sep 17 00:00:00 2001 From: Isabelle Date: Wed, 19 Nov 2025 17:17:10 +0100 Subject: [PATCH] fix: Add new IsBright helper to replace old Tools::GetBrightness This is used from prestashop itself but I needed to add it as a smarty helper --- is_themecore/src/Core/Smarty/SmartyHelperFunctions.php | 6 ++++++ is_themecore/src/Hook/Smarty.php | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php b/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php index ab209ff..a28ea5f 100644 --- a/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php +++ b/is_themecore/src/Core/Smarty/SmartyHelperFunctions.php @@ -4,6 +4,7 @@ namespace Oksydan\Module\IsThemeCore\Core\Smarty; use Oksydan\Module\IsThemeCore\Core\Webp\WebpPictureGenerator; use Oksydan\Module\IsThemeCore\Form\Settings\WebpConfiguration; +use PrestaShop\PrestaShop\Core\Util\ColorBrightnessCalculator; class SmartyHelperFunctions { @@ -189,4 +190,9 @@ class SmartyHelperFunctions return $content; } + public static function isBright($hexColor) + { + $calculator = new ColorBrightnessCalculator(); + return $calculator->isBright($hexColor); + } } diff --git a/is_themecore/src/Hook/Smarty.php b/is_themecore/src/Hook/Smarty.php index 368380b..7a9fc00 100644 --- a/is_themecore/src/Hook/Smarty.php +++ b/is_themecore/src/Hook/Smarty.php @@ -51,5 +51,10 @@ public function hookActionDispatcherBefore(): void } else { return; } + if (!isset($this->context->smarty->registered_plugins['modifier']['is_bright'])) { + $this->context->smarty->registerPlugin('modifier', 'is_bright', ['Oksydan\Module\IsThemeCore\Core\Smarty\SmartyHelperFunctions', 'isBright']); + } else { + return; + } } }