From 872e617721d5e57a822fcc3da49fee2b472f342c Mon Sep 17 00:00:00 2001 From: SharkyKZ Date: Thu, 21 Mar 2019 09:28:14 +0200 Subject: [PATCH 1/2] [4.0] Get document from application in HTMLHelper --- libraries/src/HTML/HTMLHelper.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libraries/src/HTML/HTMLHelper.php b/libraries/src/HTML/HTMLHelper.php index cf43f32ea0448..5f33d99259468 100644 --- a/libraries/src/HTML/HTMLHelper.php +++ b/libraries/src/HTML/HTMLHelper.php @@ -671,7 +671,7 @@ public static function stylesheet($file, $options = array(), $attribs = array()) } // If inclusion is required - $document = Factory::getDocument(); + $document = Factory::getApplication()->getDocument(); foreach ($includes as $include) { @@ -730,7 +730,7 @@ public static function script($file, $options = array(), $attribs = array()) } // If inclusion is required - $document = Factory::getDocument(); + $document = Factory::getApplication()->getDocument(); foreach ($includes as $include) { @@ -768,8 +768,8 @@ public static function webcomponent(string $file, array $options = []) // Script core.js is responsible for the polyfills and the async loading of the web components static::_('behavior.core'); - $version = ''; - $mediaVersion = Factory::getDocument()->getMediaVersion(); + $document = Factory::getApplication()->getDocument(); + $version = ''; // Add the css if exists self::_('stylesheet', str_replace('.js', '.css', $file), $options); @@ -791,7 +791,7 @@ public static function webcomponent(string $file, array $options = []) { if ($options['version'] === 'auto') { - $version = '?' . $mediaVersion; + $version = '?' . $document->getMediaVersion(); } else { @@ -799,10 +799,11 @@ public static function webcomponent(string $file, array $options = []) } } + $components = $document->getScriptOptions('webcomponents'); + foreach ($includes as $include) { $potential = $include . ((strpos($include, '?') === false) ? $version : ''); - $components = Factory::getDocument()->getScriptOptions('webcomponents'); if (in_array($potential, $components)) { @@ -810,8 +811,9 @@ public static function webcomponent(string $file, array $options = []) } $components[] = $potential; - Factory::getDocument()->addScriptOptions('webcomponents', $components); } + + $document->addScriptOptions('webcomponents', $components); } /** @@ -1067,7 +1069,7 @@ public static function calendar($value, $name, $id, $format = '%Y-%m-%d', $attri { $tag = Factory::getLanguage()->getTag(); $calendar = Factory::getLanguage()->getCalendar(); - $direction = strtolower(Factory::getDocument()->getDirection()); + $direction = strtolower(Factory::getApplication()->getDocument()->getDirection()); // Get the appropriate file for the current language date helper $helperPath = 'system/fields/calendar-locales/date/gregorian/date-helper.min.js'; From af7b49c9db6ef6831464024a9b8a10e1c6facb73 Mon Sep 17 00:00:00 2001 From: SharkyKZ Date: Thu, 21 Mar 2019 09:33:17 +0200 Subject: [PATCH 2/2] Move after early return --- libraries/src/HTML/HTMLHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/src/HTML/HTMLHelper.php b/libraries/src/HTML/HTMLHelper.php index 5f33d99259468..377f761230b21 100644 --- a/libraries/src/HTML/HTMLHelper.php +++ b/libraries/src/HTML/HTMLHelper.php @@ -768,9 +768,6 @@ public static function webcomponent(string $file, array $options = []) // Script core.js is responsible for the polyfills and the async loading of the web components static::_('behavior.core'); - $document = Factory::getApplication()->getDocument(); - $version = ''; - // Add the css if exists self::_('stylesheet', str_replace('.js', '.css', $file), $options); @@ -787,6 +784,9 @@ public static function webcomponent(string $file, array $options = []) return; } + $document = Factory::getApplication()->getDocument(); + $version = ''; + if (isset($options['version'])) { if ($options['version'] === 'auto')