madeyourday/contao-rocksolid-icon-picker
Contao extension providing the RockSolid Icon Picker. Install via Composer and add an icon selection field to your Contao backend/forms for use in custom content elements and other configurations. Includes English and German docs.
Installation:
composer require madeyourday/contao-rocksolid-icon-picker
Ensure your composer.json includes "minimum-stability": "dev" if using Contao 5.x.
First Use Case:
tl_content or a custom table).dca.php):
$GLOBALS['TL_DCA']['tl_content']['fields']['iconPicker'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['iconPicker'],
'inputType' => 'iconPicker',
'eval' => ['tl_class' => 'clr', 'mandatory' => false],
'options' => ['fontPath' => 'bundles/rocksolidiconpicker/font'],
];
Frontend Output: Use the icon in templates via:
<i class="icon {{ $row->iconPicker }}"></i>
Or with dynamic styling:
echo '<i class="icon ' . $this->iconPicker . '" style="color: ' . $this->iconColor . ';"></i>';
Dynamic Icon Selection:
tl_module field:
$GLOBALS['TL_DCA']['tl_module']['fields']['moduleIcon'] = [
'inputType' => 'iconPicker',
'eval' => ['mandatory' => true],
];
Theming Integration:
fontPath in DCA:
'options' => ['fontPath' => 'assets/fonts/custom-icons'],
.woff, .woff2) are accessible via the defined path. Note: WOFF2 files are now prioritized in both frontend and backend.Conditional Logic:
'eval' => [
'mandatory' => $this->isRootElement ? true : false,
'iconPicker' => ['allowBlank' => !$this->isRootElement],
],
Backend Configuration:
mandatory => false.Frontend Styling:
.icon-picked { color: var(--theme-color); }
.icon-picked:hover { transform: scale(1.1); }
Contao 4 vs. 5:
symfony/flex is configured in composer.json:
"extra": {
"contao": {
"version": "5.0"
}
}
Custom Icon Sets:
assets/fonts/ and reference them in fontPath./assets/fonts/
├── custom-icons.woff
├── custom-icons.woff2 // WOFF2 now preferred
'options' => ['fontPath' => 'assets/fonts', 'iconSet' => 'custom-icons'],
Performance:
assets.json (Contao 5) or via <link rel="preload">:
<link rel="preload" href="assets/fonts/custom-icons.woff2" as="font" type="font/woff2" crossorigin>
Font Path Issues:
fontPath points to a web-accessible directory (e.g., web/fonts/).web/fonts/), not backslashes.php contao-console cache:clear)..woff2 files exist alongside .woff files for optimal loading.Dark Mode Conflicts:
color: currentColor (default in RockSolid’s sets)..icon { color: inherit !important; }
Blank Option Missing:
mandatory => false.'iconPicker' vs. 'icon_picker').Contao 5 Symfony Mismatch:
symfony/dependency-injection and symfony/http-kernel are compatible with Contao 5.composer require symfony/dependency-injection:^6.0
composer require symfony/http-kernel:^6.0
Icon Names Merging:
custom- or myproject-).iconSet: 'custom-icons' in DCA options.Check Font Loading:
http://yoursite.com/web/fonts/custom-icons.woff2.DCA Validation:
echo '<pre>'; print_r($GLOBALS['TL_DCA']['tl_your_table']['fields']); echo '</pre>';
Clear Caches Aggressively:
php contao-console cache:clear --env=prod
php contao-console assets:generate
Custom Icon Sets:
fontPath.CustomIconPicker class to override default behavior:
class CustomIconPicker extends IconPicker {
protected function getIconOptions() {
$options = parent::getIconOptions();
$options['iconSet'] = 'my-custom-set';
$options['preferWoff2'] = true; // Explicitly enable WOFF2
return $options;
}
}
config/autoload.php:
$container->set('icon_picker', CustomIconPicker::class);
Dynamic Icon Filtering:
// In a custom JS file
$(document).on('ready.pjax', function() {
$('.icon-picker-modal').on('show', function() {
$('.icon-grid .icon').filter(':not(.fa-brands)').hide(); // Hide brands only
});
});
Backend Localization:
languages/en/tl_content.php:
$GLOBALS['TL_LANG']['tl_content']['iconPicker'] = ['Icon', 'Select an icon'];
Frontend Fallbacks:
<i class="icon {{ $row->iconPicker }} icon-fallback"></i>
<style>
.icon-fallback { background-image: url('themes/default/img/fallback-icon.svg'); }
</style>
WOFF2 Fallback Handling:
@supports not (font-variation-settings: normal)
How can I help you explore Laravel packages today?