[FEATURE] Add hook to tslib_adminpanel
authorGeorg Ringer <mail@ringerge.org>
Fri, 29 Jul 2011 13:06:24 +0000 (15:06 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 31 Jul 2011 14:00:39 +0000 (16:00 +0200)
Add a hook to the AdminPanel to allow additional
code beeing added by other extensions

Change-Id: Icec38ca8b91891a515a40ec2e8774a00cf553c40
Resolves: #28568
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/3860
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
tests/typo3/sysext/cms/tslib/class.tslib_adminpanelTest.php [new file with mode: 0644]
typo3/sysext/cms/ext_autoload.php
typo3/sysext/cms/tslib/class.tslib_adminpanel.php
typo3/sysext/cms/tslib/interfaces/interface.tslib_adminPanelHook.php [new file with mode: 0644]

diff --git a/tests/typo3/sysext/cms/tslib/class.tslib_adminpanelTest.php b/tests/typo3/sysext/cms/tslib/class.tslib_adminpanelTest.php
new file mode 100644 (file)
index 0000000..ec12c46
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2011 Christian Kuhn <lolli@schwarzbu.ch>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for the "tslib_AdminPanel" class in the TYPO3 Core.
+ *
+ * @package TYPO3
+ * @subpackage tslib
+ * @author Christian Kuhn <lolli@schwarzbu.ch>
+ */
+class tslib_AdminPanelTest extends tx_phpunit_testcase {
+
+       /**
+        * Enable backup of global and system variables
+        *
+        * @var boolean
+        */
+       protected $backupGlobals = TRUE;
+
+       /**
+        * Exclude TYPO3_DB from backup/ restore of $GLOBALS
+        * because resource types cannot be handled during serializing
+        *
+        * @var array
+        */
+       protected $backupGlobalsBlacklist = array('TYPO3_DB');
+
+       /////////////////////////////////////////////
+       // Test concerning extendAdminPanel hook
+       /////////////////////////////////////////////
+
+       /**
+        * @test
+        * @expectedException UnexpectedValueException
+        */
+       public function extendAdminPanelHookThrowsExceptionIfHookClassDoesNotImplementInterface() {
+               $hookClass = uniqid('tx_coretest');
+               eval('class ' . $hookClass . ' {}');
+
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = $hookClass;
+
+               $adminPanelMock = $this->getMock('tslib_AdminPanel', array('dummy'), array(), '', FALSE);
+               $adminPanelMock->display();
+       }
+
+       /**
+        * @test
+        */
+       public function extendAdminPanelHookCallsExtendAdminPanelMethodOfHook() {
+               $hookClass = uniqid('tx_coretest');
+               $hookMock = $this->getMock(
+                       'tslib_adminPanelHook',
+                       array(),
+                       array(),
+                       $hookClass
+               );
+               $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = $hookClass;
+
+               $adminPanelMock = $this->getMock('tslib_AdminPanel', array('dummy'), array(), '', FALSE);
+
+               $hookMock->expects($this->once())
+                       ->method('extendAdminPanel')
+                       ->with($this->isInstanceOf('tslib_AdminPanel'));
+
+               $adminPanelMock->display();
+       }
+}
+?>
\ No newline at end of file
index 5979300..8b4e486 100644 (file)
@@ -34,6 +34,7 @@ return array(
        'tslib_cobj_getimgresourcehook' => PATH_tslib . 'interfaces/interface.tslib_content_getimgresourcehook.php',
        'tslib_content_postinithook' => PATH_tslib . 'interfaces/interface.tslib_content_postinithook.php',
        'tslib_content_stdwraphook' => PATH_tslib . 'interfaces/interface.tslib_content_stdwraphook.php',
+       'tslib_adminpanelhook' => PATH_tslib . 'interfaces/interface.tslib_adminPanelHook.php',
        'user_various' => PATH_tslib . 'media/scripts/example_callfunction.php',
        'tslib_gmenu_foldout' => PATH_tslib . 'media/scripts/gmenu_foldout.php',
        'tslib_gmenu_layers' => PATH_tslib . 'media/scripts/gmenu_layers.php',
index f37efbf..24fd090 100644 (file)
@@ -277,6 +277,18 @@ class tslib_AdminPanel {
                        }
                }
 
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'] as $classRef) {
+                               $hookObject = t3lib_div::getUserObj($classRef);
+
+                               if (!($hookObject instanceof tslib_adminPanelHook)) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface tslib_adminPanelHook', 1311942539);
+                               }
+
+                               $moduleContent = $hookObject->extendAdminPanel($this);
+                       }
+               }
+
                $row = $this->extGetLL('adminPanelTitle') . ': <span class="typo3-adminPanel-beuser">' .
                        htmlspecialchars($GLOBALS['BE_USER']->user['username']) . '</span>';
 
@@ -621,10 +633,9 @@ $query . '<table class="typo3-adminPanel">' .
         *
         * @param       string          The suffix to the display_ label. Also selects the label from the LOCAL_LANG array.
         * @return      string          HTML table row.
-        * @access private
         * @see extGetItem()
         */
-       protected function extGetHead($sectionSuffix) {
+       public function extGetHead($sectionSuffix) {
                $settingName = 'display_' . $sectionSuffix;
                $isVisible = $GLOBALS['BE_USER']->uc['TSFE_adminConfig'][$settingName];
                $cssClassName = 'typo3-adminPanel-section-' . ($isVisible ? 'open' : 'closed');
@@ -641,10 +652,9 @@ $query . '<table class="typo3-adminPanel">' .
         * @param       string          The code for the display_ label/key
         * @param       string          Input string
         * @return      string          Linked input string
-        * @access private
         * @see extGetHead()
         */
-       protected function linkSectionHeader($sectionSuffix, $sectionTitle, $className = '') {
+       public function linkSectionHeader($sectionSuffix, $sectionTitle, $className = '') {
                return '<div class="typo3-adminPanel-label"><a href="javascript:void(0)" onclick="' .
                        htmlspecialchars('document.TSFE_ADMIN_PANEL_FORM[\'TSFE_ADMIN_PANEL[display_' . $sectionSuffix . ']\'].value=' . ($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['display_' . $sectionSuffix] ? '0' : '1') . ';document.TSFE_ADMIN_PANEL_FORM.submit();return false;') .
                        '"' . ($className ? ' class="' . $className . '"' : '') . '>' . $sectionTitle . '</a></div>';
@@ -657,10 +667,9 @@ $query . '<table class="typo3-adminPanel">' .
         * @param       string          Key to label
         * @param       string          The HTML content for the forth table cell.
         * @return      string          HTML table row.
-        * @access private
         * @see extGetHead()
         */
-       protected function extGetItem($title, $content = '', $checkboxContent = '') {
+       public function extGetItem($title, $content = '', $checkboxContent = '') {
                $out = '<tr class="typo3-adminPanel-itemRow">' .
                        '<td class="typo3-adminPanel-section-content">' . $checkboxContent . ($title ? $this->extGetLL($title) : '&nbsp;') . $content . '</td></tr>';
 
@@ -741,7 +750,7 @@ $query . '<table class="typo3-adminPanel">' .
         * @param       string          Key for a label in the $LOCAL_LANG array of "sysext/lang/locallang_tsfe.php"
         * @return      string          The value for the $key
         */
-       protected function extGetLL($key) {
+       public function extGetLL($key) {
                $labelStr = htmlspecialchars($GLOBALS['LANG']->getLL($key));    // Label string in the default backend output charset.
 
                        // Convert to utf-8, then to entities:
diff --git a/typo3/sysext/cms/tslib/interfaces/interface.tslib_adminPanelHook.php b/typo3/sysext/cms/tslib/interfaces/interface.tslib_adminPanelHook.php
new file mode 100644 (file)
index 0000000..b7ad90f
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2011 Georg Ringer <typo3@ringerge.org>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Interface for classes which hook into tslib_adminpanel
+ *
+ * @author Georg Ringer <typo3@ringerge.org>
+ * @package TYPO3
+ * @subpackage cms
+ */
+interface tslib_adminPanelHook {
+
+       /**
+        * Extend the adminPanel
+        *
+        * @param tslib_AdminPanel The adminPanel object
+        * @return string Returns additional code
+        */
+       public function extendAdminPanel(tslib_AdminPanel $obj);
+}
+?>
\ No newline at end of file