From 947031d9f84c67cdd0e1e424a49761131735097d Mon Sep 17 00:00:00 2001
From: Benjamin Mack <benni@typo3.org>
Date: Wed, 25 Feb 2015 18:37:50 +0100
Subject: [PATCH] [TASK] Streamline TS registration for sysexts

For historical reasons the "Static Template #43"
was "content.default" and the possibility to add
TypoScript after this default rendering was introduced
in order to have CTypes and plugins register their
TypoScript just after e.g. "content.default" or
"css_styled_content".

Since TYPO3 CMS 6.2 the preferred option is
called "defaultContentRendering" instead of
the magic number "43".

Some leftover parts in sysexts are replaced
with "defaultContentRendering", as well
as some more descriptive information on
how the legacy number exists.

Releases: master
Resolves: #65346
Change-Id: I7268ec9ee8454d1eb4b0fda9f12fdfb5cb191ba8
Reviewed-on: http://review.typo3.org/37239
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
---
 .../Utility/ExtensionManagementUtility.php    | 21 ++++++++++------
 .../Classes/Utility/ExtensionUtility.php      |  9 +++----
 .../Unit/Utility/ExtensionUtilityTest.php     | 10 ++++----
 typo3/sysext/felogin/ext_localconf.php        | 25 +++++++++----------
 typo3/sysext/rtehtmlarea/ext_localconf.php    |  4 +--
 5 files changed, 37 insertions(+), 32 deletions(-)

diff --git a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
index 2067b6de6610..78e7be1cceaf 100644
--- a/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
+++ b/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
@@ -1273,10 +1273,16 @@ class ExtensionManagementUtility {
 	}
 
 	/**
-	 * Add PlugIn to Static Template #43
+	 * Add PlugIn to the default template rendering (previously called "Static Template #43")
 	 *
 	 * When adding a frontend plugin you will have to add both an entry to the TCA definition of tt_content table AND to the TypoScript template which must initiate the rendering.
-	 * Since the static template with uid 43 is the "content.default" and practically always used for rendering the content elements it's very useful to have this function automatically adding the necessary TypoScript for calling your plugin. It will also work for the extension "css_styled_content"
+	 *
+	 * The naming of #43 has historic reason and is rooted inside code which is now put into a TER extension called
+	 * "statictemplates". Since the static template with uid 43 is the "content.default" and practically always used
+	 * for rendering the content elements it's very useful to have this function automatically adding the necessary
+	 * TypoScript for calling your plugin. It will also work for the extension "css_styled_content".
+	 * The logic is now generalized and called "defaultContentRendering", see addTypoScript() as well.
+	 *
 	 * $type determines the type of frontend plugin:
 	 * + list_type (default) - the good old "Insert plugin" entry
 	 * + menu_type - a "Menu/Sitemap" entry
@@ -1307,7 +1313,7 @@ plugin.' . $cN . $suffix . ' {
 		self::addTypoScript($key, 'setup', '
 # Setting ' . $key . ' plugin TypoScript
 ' . $pluginContent);
-		// After ST43
+		// Add after defaultContentRendering
 		switch ($type) {
 			case 'list_type':
 				$addLine = 'tt_content.list.20.' . $key . $suffix . ' = < plugin.' . $cN . $suffix;
@@ -1337,7 +1343,7 @@ tt_content.' . $key . $suffix . ' {
 			self::addTypoScript($key, 'setup', '
 # Setting ' . $key . ' plugin TypoScript
 ' . $addLine . '
-', 43);
+', 'defaultContentRendering');
 		}
 	}
 
@@ -1395,7 +1401,8 @@ tt_content.' . $key . $suffix . ' {
 	 * possible that a first extension like css_styled_content registers a "contentRendering" template (= a template that defines default content rendering TypoScript)
 	 * by adding itself to $TYPO3_CONF_VARS[FE][contentRenderingTemplates][] = 'myext/Configuration/TypoScript'.
 	 * An extension calling addTypoScript('myext', 'setup', $typoScript, 'defaultContentRendering') will add its TypoScript directly after;
-	 * For now, "43" and "defaultContentRendering" can be used, but defaultContentRendering is more descriptive and should be used in the future
+	 * For now, "43" and "defaultContentRendering" can be used, but "defaultContentRendering" is more descriptive and
+	 * should be used in the future.
 	 *
 	 * @param string $key Is the extension key (informative only).
 	 * @param string $type Is either "setup" or "constants" and obviously determines which kind of TypoScript code we are adding.
@@ -1417,8 +1424,8 @@ tt_content.' . $key . $suffix . ' {
 			if ($afterStaticUid) {
 				$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.'][$afterStaticUid] .= $content;
 				// If 'content (default)' is targeted (static uid 43),
-				// the content is added after typoscript of type contentRendering, eg. css_styled_content, see EXT:frontend/TemplateService for that
-				if ($afterStaticUid == 43 || $afterStaticUid === 'defaultContentRendering') {
+				// the content is added after typoscript of type contentRendering, eg. css_styled_content, see EXT:frontend/TemplateService for more information on how the code is parsed
+				if ($afterStaticUid === 'defaultContentRendering' || $afterStaticUid == 43) {
 					$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_' . $type . '.']['defaultContentRendering'] .= $content;
 				}
 			} else {
diff --git a/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php b/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php
index b00688bff36e..214a9ac5fea3 100644
--- a/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php
+++ b/typo3/sysext/extbase/Classes/Utility/ExtensionUtility.php
@@ -28,10 +28,9 @@ class ExtensionUtility {
 	 *
 	 * When adding a frontend plugin you will have to add both an entry to the TCA definition
 	 * of tt_content table AND to the TypoScript template which must initiate the rendering.
-	 * Since the static template with uid 43 is the "content.default" and practically always
-	 * used for rendering the content elements it's very useful to have this function automatically
-	 * adding the necessary TypoScript for calling the appropriate controller and action of your plugin.
-	 * It will also work for the extension "css_styled_content"
+	 * Including the plugin code after "defaultContentRendering" adds the necessary TypoScript
+	 * for calling the appropriate controller and action of your plugin.
+	 * This means, it will also work for the extension "css_styled_content"
 	 * FOR USE IN ext_localconf.php FILES
 	 * Usage: 2
 	 *
@@ -99,7 +98,7 @@ tt_content.' . $pluginSignature . ' {
 		$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['pluginType'] = $pluginType;
 		\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($extensionName, 'setup', '
 # Setting ' . $extensionName . ' plugin TypoScript
-' . $pluginContent, 43);
+' . $pluginContent, 'defaultContentRendering');
 	}
 
 	/**
diff --git a/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php b/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php
index ba9cd526e430..6e97e451465c 100644
--- a/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php
+++ b/typo3/sysext/extbase/Tests/Unit/Utility/ExtensionUtilityTest.php
@@ -61,7 +61,7 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 	public function configurePluginWorksForMinimalisticSetup() {
 		$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
 		\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array('Blog' => 'index'));
-		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
 		$this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
 		$this->assertContains('
 	userFunc = TYPO3\\CMS\\Extbase\\Core\\Bootstrap->run
@@ -77,7 +77,7 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 	public function configurePluginCreatesCorrectDefaultTypoScriptSetup() {
 		$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'] = array();
 		\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array('Blog' => 'index'));
-		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
 		$defaultTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'];
 		$this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
 	}
@@ -91,7 +91,7 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('MyExtension', 'Pi1', array(
 			'FirstController' => 'index'
 		));
-		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
 		$this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
 		$this->assertContains('
 	extensionName = MyExtension
@@ -140,7 +140,7 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		), array(
 			'FirstController' => 'index,show'
 		));
-		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
 		$this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
 		$this->assertContains('
 	extensionName = MyExtension
@@ -168,7 +168,7 @@ class ExtensionUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 		), array(
 			'FirstController' => 'new,show'
 		));
-		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['43'];
+		$staticTypoScript = $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
 		$this->assertContains('tt_content.list.20.myextension_pi1 = USER', $staticTypoScript);
 		$this->assertContains('
 	extensionName = MyExtension
diff --git a/typo3/sysext/felogin/ext_localconf.php b/typo3/sysext/felogin/ext_localconf.php
index 1c1b043775de..6e672d8898cb 100644
--- a/typo3/sysext/felogin/ext_localconf.php
+++ b/typo3/sysext/felogin/ext_localconf.php
@@ -1,26 +1,25 @@
 <?php
 defined('TYPO3_MODE') or die();
 
-//replace old Login
-$pluginContent = trim('
+// add plugin controller
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('TYPO3.CMS.Felogin', 'setup', '
+# Setting "felogin" plugin TypoScript
 plugin.tx_felogin_pi1 = USER_INT
-plugin.tx_felogin_pi1 {
-	userFunc = TYPO3\\CMS\\Felogin\\Controller\\FrontendLoginController->main
-}
+plugin.tx_felogin_pi1.userFunc = TYPO3\\CMS\\Felogin\\Controller\\FrontendLoginController->main
 ');
-\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($_EXTKEY, 'setup', '
-# Setting ' . $_EXTKEY . ' plugin TypoScript
-' . $pluginContent);
-$addLine = '
+
+// Add a default TypoScript for the CType "login" (also replaces history login functionality)
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('TYPO3.CMS.Felogin', 'setup', '
+# Setting "felogin" plugin TypoScript
 tt_content.login = COA
 tt_content.login {
-	10 = < lib.stdheader
+	10 =< lib.stdheader
 	20 >
-	20 = < plugin.tx_felogin_pi1
+	20 =< plugin.tx_felogin_pi1
 }
-';
-\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($_EXTKEY, 'setup', '# Setting ' . $_EXTKEY . ' plugin TypoScript' . $addLine . '', 43);
+', 'defaultContentRendering');
 
+// add login to new content element wizard
 if (TYPO3_MODE === 'BE') {
 	\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('
 	mod.wizards.newContentElement.wizardItems.forms {
diff --git a/typo3/sysext/rtehtmlarea/ext_localconf.php b/typo3/sysext/rtehtmlarea/ext_localconf.php
index 4062ec8e0e29..fc7f3b4cb736 100644
--- a/typo3/sysext/rtehtmlarea/ext_localconf.php
+++ b/typo3/sysext/rtehtmlarea/ext_localconf.php
@@ -119,7 +119,7 @@ if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['enableImages']) {
 	}
 }
 // Add frontend image rendering TypoScript anyways
-\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('rtehtmlarea', 'setup', '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:rtehtmlarea/Configuration/TypoScript/ImageRendering/setup.txt">', 43);
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('rtehtmlarea', 'setup', '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:rtehtmlarea/Configuration/TypoScript/ImageRendering/setup.txt">', 'defaultContentRendering');
 
 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['DefaultLink'] = array();
 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['DefaultLink']['objectReference'] = '&' . \TYPO3\CMS\Rtehtmlarea\Extension\DefaultLink::class;
@@ -135,7 +135,7 @@ $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['plugins']['TYPO3Link']['a
 $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['enableAccessibilityIcons'] = $_EXTCONF['enableAccessibilityIcons'] ?: 0;
 if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['enableAccessibilityIcons']) {
 	\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:rtehtmlarea/Configuration/PageTS/AccessibilityIcons/pageTSConfig.txt">');
-	\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('rtehtmlarea', 'setup', '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:rtehtmlarea/res/accessibilityicons/setup.txt">', 43);
+	\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript('rtehtmlarea', 'setup', '<INCLUDE_TYPOSCRIPT: source="FILE:EXT:rtehtmlarea/res/accessibilityicons/setup.txt">', 'defaultContentRendering');
 }
 
 // Register features that use the style attribute
-- 
GitLab