[TYPO3-core] RFC: feature request: user function for t3lib_iconworks::getIcon

Wolfgang Klinger wolfgang at stufenlos.net
Fri Sep 1 10:28:42 CEST 2006


 *hiya!*

 Feature request (trunk only)

 It's not possible to overwrite t3lib_iconworks::getIcon as it's always
 called statically.

 Therefore I propose the attached patch to allow a user function to
 decide which icon to use.

 Example:

---- Page TS:
options.getIconUserFunction = EXT:user_mystuff/mystuff.php:&user_mystuff->getIconUserFunction
----

 (I don't know if the "options." realm is the right one, any suggestions for
 improvement?)

---- user function
class user_mystuff {
    function getIconUserFunction(&$params, &$ref) {
        $page_info = t3lib_beFunc::getRecord('pages', $params['row']['uid']);
        if ($page_info['tx_rlmptmplselector_ca_tmpl'] == '1column_image.html') {
            $iconfile = t3lib_extMgm::extRelPath('user_mystuff').'pages_1column.gif';
        }
        if ($page_info['tx_rlmptmplselector_ca_tmpl'] == '2columns.html') {
            $iconfile = t3lib_extMgm::extRelPath('user_mystuff').'pages_2columns.gif';
        }

        if (strlen($iconfile)) {
            $params['doNotGenerateIcon'] = FALSE;
            $params['iconfile'] = $iconfile;
        }
    }
}
----

 I added the possibility to change "doNotGenerateIcon" here (overriding
 the value set in $TYPO3_CONF_VARS['GFX']['noIconProc']) in order to
 allow "hidden" and other states applied to my custom icon
 even if all the other icons should be served in their static version
 (don't know if that's "allowed"?).


 tia 
 bye Wolfgang

 ps: I need the previous patch (call_user_func_array) in order to make 
 this work at all!

-------------- next part --------------
Index: t3lib/class.t3lib_iconworks.php
===================================================================
--- t3lib/class.t3lib_iconworks.php     (revision 1700)
+++ t3lib/class.t3lib_iconworks.php     (working copy)
@@ -130,20 +130,35 @@
                        return 'gfx/i/shadow_delete.png';
                }

-                       // First, find the icon file name. This can depend on configuration in TCA, field values and more:
-               if ($table=='pages')    {
-                       if ($row['nav_hide'] && ($row['doktype']==1||$row['doktype']==2))       $row['doktype']=5;      // Workaround to change the icon if "H
ide in menu" was set
+               $pageTS = t3lib_BEFunc::getPagesTSconfig($row['uid']);
+               $userFunction = isset($pageTS['options.']['getIconUserFunction']) ? $pageTS['options.']['getIconUserFunction'] : '';

-                       if (!$iconfile = $PAGES_TYPES[$row['doktype']]['icon']) {
-                               $iconfile = $PAGES_TYPES['default']['icon'];
+               $params = Array('row' => $row, 'iconfile' => '', 'doNotGenerateIcon' => $doNotGenerateIcon);
+               if (strlen($userFunction)) {
+                       t3lib_div::callUserFunction($userFunction, $params, $this);
+
+                       $doNotGenerateIcon = $params['doNotGenerateIcon'];
+                       if (strlen($params['iconfile'])) {
+                               $iconfile = $params['iconfile'];
                        }
-                       if ($row['module'] && $ICON_TYPES[$row['module']]['icon'])      {
-                               $iconfile = $ICON_TYPES[$row['module']]['icon'];
+               }
+
+               if (!strlen($iconfile)) {
+                               // First, find the icon file name. This can depend on configuration in TCA, field values and more:
+                       if ($table=='pages')    {
+                               if ($row['nav_hide'] && ($row['doktype']==1||$row['doktype']==2))       $row['doktype']=5;      // Workaround to change the ic
on if "Hide in menu" was set
+
+                               if (!$iconfile = $PAGES_TYPES[$row['doktype']]['icon']) {
+                                       $iconfile = $PAGES_TYPES['default']['icon'];
+                               }
+                               if ($row['module'] && $ICON_TYPES[$row['module']]['icon'])      {
+                                       $iconfile = $ICON_TYPES[$row['module']]['icon'];
+                               }
+                       } else {
+                               if (!$iconfile = $TCA[$table]['ctrl']['typeicons'][$row[$TCA[$table]['ctrl']['typeicon_column']]])      {
+                                       $iconfile = (($TCA[$table]['ctrl']['iconfile']) ? $TCA[$table]['ctrl']['iconfile'] : $table.'.gif');
+                               }
                        }
-               } else {
-                       if (!$iconfile = $TCA[$table]['ctrl']['typeicons'][$row[$TCA[$table]['ctrl']['typeicon_column']]])      {
-                               $iconfile = (($TCA[$table]['ctrl']['iconfile']) ? $TCA[$table]['ctrl']['iconfile'] : $table.'.gif');
-                       }
                }

                        // Setting path of iconfile if not already set. Default is "gfx/i/"
@@ -527,4 +542,4 @@
                }
        }
 }
-?>
\ No newline at end of file
+?>


More information about the TYPO3-team-core mailing list