Building a TYPO3 extension in Extbase/Fluid

Add icons to extension storage folders in page tree

Using multiple extensions with its own records probably leaves you with quite a list of Storage Folders. Adding custom icons makes you recognize the desired folder faster. This way should be working in TYPO3 7 and later.

All file paths are relative to the root of your extension /typo3conf/ext/your_extension/

1. Store your extension icons in /Resources/Public/Icons/

2. Register all icons in your extension’s /ext_localconf.php

Add the following code:
<?php
if (TYPO3_MODE === 'BE') {
        /**
         * register icons
         * Icon for plugin selection in content element will be loaded automatically
         *     if to be found in /Resources/Public/Icons/Extension.svg
         */

        $ext = 'yourextension';
        $icons = [
                $ext . '-record-folder' => 'extension-record-folder.svg',
                $ext . '-model-whatever' => 'model-whatever.svg',
        ];
        $iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
        foreach ($icons AS $id => $filename) {
                $iconRegistry->registerIcon(
                        $id,
                        $iconRegistry->detectIconProvider($filename),
                        ['source' => 'EXT:' . $ext . '/Resources/Public/Icons/' . $filename]
                );
        }
}
        }
}
  • you can use all standard file formats for the icons like svg, png, gif, jpg; the $iconRegistry->detectIconProvider method will choose the right provider (there is a different one for svg files than for bitmap files)

3. Add a TCE override for the pages table

Path: /Configuration/TCA/Overrides/pages.php

<?php
defined('TYPO3_MODE') or die();

/**
 * Override icon for storage folder
 */


$ext = 'yourextension';
$iconRef = $ext . '-record-folder';

$addToModuleSelection = true;
foreach ($GLOBALS['TCA']['pages']['columns']['module']['config']['items'] as $item) {
    if ($item['1'] == $ext) {
        $addToModuleSelection = false;
        break;
    }
}

if ($addToModuleSelection) {
        $GLOBALS['TCA']['pages']['ctrl']['typeicon_classes']['contains-' . $ext] = $iconRef;
        $GLOBALS['TCA']['pages']['columns']['module']['config']['items'][] = [
            0 => 'LLL:EXT:' . $ext . '/Resources/Private/Language/locallang_be.xlf:extension_name',
            1 => $ext,
            2 => $iconRef
        ];
}
        ];
}
  • make sure to use the same name for your extension as in /ext_localconf.php (variable $ext)
  • $iconRef must be the identifier you chose for the folder icon in your /ext_localconf.php
  • $GLOBALS['TCA']['pages']['columns']['module']['config']['items'][][0] is the name of your extension that will appear in the selection list; make sure to add the localisation to your /Resources/Private/Language/locallang_be.xlf (or however your backend language file is called, which will often be locallang_db.xlf), in this case it would be 'extension_name' but of course it can be whatever you want as long as you call it by that name in this array variable

4. Select the icon for your Storage Folder or Page

Edit the Page Properties of the Storage Folder or Page where you store your extension records. Go to Behaviour tab and select the extension under “Use as Container”. Needless to say TYPO3 needs extensive cache flushing before you’ll be able to see the extension in the list, of course. And if, in the page tree, you see a default error icon instead of the folder icon after you saved the properties – just reload again. And again. Might help, might not.