[TYPO3-dev] How to add custom overlays to Backend sprite icons?

Dirk Wenzel wenzel at webfox03.de
Mon Mar 2 21:12:58 CET 2015


Here comes what I missed:
Icons for overlays are registred like any other icon:
SpriteManager::addSingleIcons(
  array('<iconName>' => '<pathToIconFile>')
);

In my example the following lines in ext_tables.php are necessary:
\TYPO3\CMS\Backend\Sprite\SpriteManager::addSingleIcons(
array(
   'status-overlay-is-duplicate' => 
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) .
   'Resources/Public/Icons/icon-overlay-is-duplicate.png',
),
$_EXTKEY
);

The now registred icon will be available under a name build by the rule:
'extensions-<extensionName>-<iconName>'
In my example under:
'extensions-<extensionName>-statusoverlay-is-duplicate'

Therefore I have to set in ext_tables.php:
$GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayNames']['isDuplicate'] 
= 'extensions-<extensionName>-status-overlay-is-duplicate';

Cheers
Dirk

Am 28.02.15 13:14, schrieb Dirk Wenzel:
> Hi all,
> I would like to add a custom overlay to record icons in Backend
> reflecting a certain state of records.
>
> What I achieved so far:
> There is a hook called overrideIconOverlay in
> TYPO3\CMS\Backend\Utility\IconUtility::mapRecordOverlayToSpriteIconName(...)
> which allows to add a status.
>
> I added my status field (is_duplicate) to the enablecolumns of its TCA:
> $TCA['<tableName>']['ctrl‘]['enablecolumns'] = array(
>    'disabled' => 'hidden',
>    'starttime' => 'starttime',
>    'endtime' => 'endtime',
>    'is_duplicate' => 'is_duplicate'
> );
>
> implemented a hook method:
> class IconUtilityHook {
>    /**
>    * Override Icon Overlay
>    * Sets a status which can be interpreted by the
>    * IconUtility for rendering an overlay
>    *
>    * @param \string $table
>    * @param \array $row
>    * @param \array $status
>    */
>    public function overrideIconOverlay(&$table, &$row, &$status) {
>      if ((bool)$row['is_duplicate']) {
>        $status['isDuplicate'] = TRUE;
>      }
>    }
> }
>
> and registred it:
> +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_iconworks.php']['overrideIconOverlay']['<extensionName>']
> = '<Vendor>\\<Package>\\Hooks\\IconUtilityHook';
>
> Further I added a priority and name for the overlay
> $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayPriorities'][]
> = 'isDuplicate';
> $GLOBALS['TBE_STYLES']['spriteIconApi']['spriteIconRecordOverlayNames']['isDuplicate']
> = 'status-overlay-is-duplicate';
>
> But it seems that the IconUtility does not provide a way to register an
> image for this overlay. In its method getIcon(...) the default enable
> fields are evaluated. If any is set IconUtility::makeIcon(...) is called
> with a matching argument $mode. There is a switch which chooses the
> matching icon file (for known states):
>
> if ($mode) {
>   unset($ol_im);
>   switch ($mode) {
>     case 'deleted':
>       $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'].
>         'gfx/overlay_deleted.gif');
>       break;
>     case 'futuretiming':
>     $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] .
>         'gfx/overlay_timing.gif');
>       break;
>     case 'timing': $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'].
>        'gfx/overlay_timing.gif');
>       break;
>     case 'hiddentiming':
>        $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] .
>         'gfx/overlay_hidden_timing.gif');
>       break;
>     case 'no_icon_found':
>        $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] .
>         'gfx/overlay_no_icon_found.gif');
>       break;
>     case 'disabled': // is already greyed - nothing more
>       $ol_im = 0;
>       break;
>     case 'hidden':
>     default:
>       $ol_im = self::imagecreatefrom($GLOBALS['BACK_PATH'] .
>        'gfx/overlay_hidden.gif');
> }
> But there is no case for custom overlay icons. This results in
> displaying my state with the no_icon_found overlay.
>
> Did I miss something? Is there any way to register an overlay icon and
> state?
>
> Thanks in advance
> Dirk



More information about the TYPO3-dev mailing list