[FEATURE] Add hook to override icon status overlay
authorFrancois Suter <francois@typo3.org>
Tue, 5 Apr 2011 13:12:39 +0000 (15:12 +0200)
committerOliver Hader <oliver@typo3.org>
Fri, 6 May 2011 16:31:13 +0000 (18:31 +0200)
Icons status overlays are defined in t3lib_iconWorks::
mapRecordOverlayToSpriteIconName(). However it is necessary
for "external" process (e.g. versioning) to override the
icon status. Currently a deleted record in a workspace will
not appear properly overlaid because only deleted = 1 is
checked and not also t3ver_state = 2. This hook makes it
possible for the version sysext to hook into the process and
set the right status.

Change-Id: Ie8603cf58dddc4159fd5198d97191ba607009475
Resolves: #25765
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/1921
Tested-by: Oliver Hader
Reviewed-by: Oliver Hader
t3lib/class.t3lib_iconworks.php
tests/t3lib/t3lib_iconWorksTest.php

index fa9535e..17f9140 100644 (file)
@@ -968,6 +968,17 @@ final class t3lib_iconWorks {
                        $status['protectedSection'] = TRUE;
                }
 
+                       // Hook: allow some other process to influence the choice of icon overlay
+                       // The method called receives the table name, the current row and the current status array as parameters
+                       // The status array should be passed as a reference and in order to be modified within the hook
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'] as $classRef) {
+                               $hookObject = t3lib_div::getUserObj($classRef);
+                               if (method_exists($hookObject, 'overrideIconOverlay')) {
+                                       $hookObject->overrideIconOverlay($table, $row, $status);
+                               }
+                       }
+               }
 
                        // now only show the status with the highest priority
                $priorities = $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayPriorities'];
index 7338a22..847d2c5 100644 (file)
@@ -431,5 +431,33 @@ class t3lib_iconWorksTest extends tx_phpunit_testcase {
                        $result
                );
        }
+
+       /**
+        * Tests whether a overrideIconOverlay hook is called.
+        * @test
+        */
+       public function isOverrideIconOverlayHookCalled() {
+               $classReference = uniqid('user_overrideIconOverlayHook');
+
+               $hookMock = $this->getMock($classReference, array('overrideIconOverlay'), array());
+               $hookMock->expects($this->once())->method('overrideIconOverlay');
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'][$classReference] = $classReference;
+               $GLOBALS['T3_VAR']['getUserObj'][$classReference] = $hookMock;
+
+               t3lib_iconWorks::mapRecordOverlayToSpriteIconName('tt_content', array());
+       }
+
+       /**
+        * Tests whether a faulty overrideIconOverlay hook (the hook object cannot be found) is not called.
+        * @test
+        */
+       public function isFaultyOverrideIconOverlayHookNotCalled() {
+               $classReference = uniqid('user_overrideIconOverlayHook');
+
+               $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay'][$classReference] = $classReference;
+               $GLOBALS['T3_VAR']['getUserObj'][$classReference] = new stdClass();
+
+               t3lib_iconWorks::mapRecordOverlayToSpriteIconName('tt_content', array());
+       }
 }
 ?>