From 6740ab8e42c64996d2d134b5b0b62733a4c84e12 Mon Sep 17 00:00:00 2001 From: Tony Air Date: Fri, 21 Jun 2024 00:48:01 +0200 Subject: [PATCH] IMPR: Allow blocking Deffered Requirements --- src/Templates/DeferredRequirements.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Templates/DeferredRequirements.php b/src/Templates/DeferredRequirements.php index a7587b7..2de992c 100755 --- a/src/Templates/DeferredRequirements.php +++ b/src/Templates/DeferredRequirements.php @@ -14,6 +14,7 @@ use SilverStripe\FontAwesome\FontAwesomeField; class DeferredRequirements implements TemplateGlobalProvider { + private static $blocked = []; private static $css = []; private static $js = []; private static $deferred = false; @@ -161,8 +162,18 @@ class DeferredRequirements implements TemplateGlobalProvider return self::forTemplate(); } + public static function block($path): void + { + self::$blocked[] = $path; + } + + public static function loadCSS($css): void { + if (in_array($css, self::$blocked)) { + return; + } + $external = (mb_strpos($css, '//') === 0 || mb_strpos($css, 'http') === 0); //if (self::getDeferred() && !self::webpackActive()) { if ((self::getDeferred() && !self::webpackActive()) || $external) { @@ -174,6 +185,10 @@ class DeferredRequirements implements TemplateGlobalProvider public static function loadJS($js): void { + if (in_array($js, self::$blocked)) { + return; + } + /*$external = (mb_substr($js, 0, 2) === '//' || mb_substr($js, 0, 4) === 'http'); if ($external || (self::getDeferred() && !self::_webpackActive())) {*/ // webpack supposed to load external JS