From a244e1ad67d4c756a4260c90afce6f92a0327009 Mon Sep 17 00:00:00 2001
From: Jonas Eberle <flightvision@googlemail.com>
Date: Sat, 28 Mar 2020 21:10:35 +0100
Subject: [PATCH] [TASK] Add documentation for AssetCollector
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This adds phpdoc for the public AssetCollector::add...() functions and
notes for users migrating from PageRenderer::add...().

Resolves: #90870
Releases: master
Change-Id: I8896b83f172a0e70ff5bdae61106c3a66d29667c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63970
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../core/Classes/Page/AssetCollector.php      | 28 ++++++++++++++++
 .../Feature-90522-IntroduceAssetCollector.rst | 33 +++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/typo3/sysext/core/Classes/Page/AssetCollector.php b/typo3/sysext/core/Classes/Page/AssetCollector.php
index c87f539dc0b3..2ffc17be6782 100644
--- a/typo3/sysext/core/Classes/Page/AssetCollector.php
+++ b/typo3/sysext/core/Classes/Page/AssetCollector.php
@@ -65,6 +65,13 @@ class AssetCollector implements SingletonInterface
      */
     protected $media = [];
 
+    /**
+     * @param string $identifier
+     * @param string $source URI to JavaScript file (allows EXT: syntax)
+     * @param array $attributes additional HTML <script> tag attributes
+     * @param array $options ['priority' => true] means rendering before other tags
+     * @return AssetCollector
+     */
     public function addJavaScript(string $identifier, string $source, array $attributes = [], array $options = []): self
     {
         $existingAttributes = $this->javaScripts[$identifier]['attributes'] ?? [];
@@ -79,6 +86,13 @@ class AssetCollector implements SingletonInterface
         return $this;
     }
 
+    /**
+     * @param string $identifier
+     * @param string $source JavaScript code
+     * @param array $attributes additional HTML <script> tag attributes
+     * @param array $options ['priority' => true] means rendering before other tags
+     * @return AssetCollector
+     */
     public function addInlineJavaScript(string $identifier, string $source, array $attributes = [], array $options = []): self
     {
         $existingAttributes = $this->inlineJavaScripts[$identifier]['attributes'] ?? [];
@@ -93,6 +107,13 @@ class AssetCollector implements SingletonInterface
         return $this;
     }
 
+    /**
+     * @param string $identifier
+     * @param string $source URI to stylesheet file (allows EXT: syntax)
+     * @param array $attributes additional HTML <link> tag attributes
+     * @param array $options ['priority' => true] means rendering before other tags
+     * @return AssetCollector
+     */
     public function addStyleSheet(string $identifier, string $source, array $attributes = [], array $options = []): self
     {
         $existingAttributes = $this->styleSheets[$identifier]['attributes'] ?? [];
@@ -107,6 +128,13 @@ class AssetCollector implements SingletonInterface
         return $this;
     }
 
+    /**
+     * @param string $identifier
+     * @param string $source stylesheet code
+     * @param array $attributes additional HTML <link> tag attributes
+     * @param array $options ['priority' => true] means rendering before other tags
+     * @return AssetCollector
+     */
     public function addInlineStyleSheet(string $identifier, string $source, array $attributes = [], array $options = []): self
     {
         $existingAttributes = $this->inlineStyleSheets[$identifier]['attributes'] ?? [];
diff --git a/typo3/sysext/core/Documentation/Changelog/10.3/Feature-90522-IntroduceAssetCollector.rst b/typo3/sysext/core/Documentation/Changelog/10.3/Feature-90522-IntroduceAssetCollector.rst
index 43fcb7539d04..8431547d2c3f 100644
--- a/typo3/sysext/core/Documentation/Changelog/10.3/Feature-90522-IntroduceAssetCollector.rst
+++ b/typo3/sysext/core/Documentation/Changelog/10.3/Feature-90522-IntroduceAssetCollector.rst
@@ -64,6 +64,39 @@ There are also two new ViewHelpers, the :html:`<f:asset.css>` and the - :html:`<
       alert('hello world');
    </f:asset.script>
 
+Considerations
+--------------
+
+Currently, assets registered with the AssetCollector are not included in callbacks of these hooks:
+
+- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler']`
+- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler']`
+- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler']`
+- :php:`$GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler']`
+
+Currently, CSS and JavaScript registered with the AssetCollector will always be rendered after their
+PageRenderer counterparts. The order is:
+
+- :html:`<head>`
+- :ts:`page.includeJSLibs.forceOnTop`
+- :ts:`page.includeJSLibs`
+- :ts:`page.includeJS.forceOnTop`
+- :ts:`page.includeJS`
+- :php:`AssetCollector::addJavaScript()` with 'priority'
+- :ts:`page.jsInline`
+- :php:`AssetCollector::addInlineJavaScript()` with 'priority'
+- :html:`</head>`
+
+- :ts:`page.includeJSFooterlibs.forceOnTop`
+- :ts:`page.includeJSFooterlibs`
+- :ts:`page.includeJSFooter.forceOnTop`
+- :ts:`page.includeJSFooter`
+- :php:`AssetCollector::addJavaScript()`
+- :ts:`page.jsFooterInline`
+- :php:`AssetCollector::addInlineJavaScript()`
+
+Currently, JavaScript registered with AssetCollector is not affected by
+:ts:`config.moveJsFromHeaderToFooter`.
 
 Examples
 --------
-- 
GitLab