Adds a DropdownImageField field which enables you to display images alongside the captions.
Uses a plugin for Chosen.js (which is used by SS), Image-Select. The plugin is modified.
SilverStripe 6
composer require fullscreeninteractive/silverstripe-dropdownimagefieldExample:
DropdownImageField::create('Icon', 'Select icon')
->setSourceList($this->getAvailableIcons())
...
/**
* Get the available icons for the dropdown
*
* @return ArrayList<ArrayData>
*/
public function getAvailableIcons(): ArrayList
{
$list = ArrayList::create();
$icons = [
'car' => '/_resources/app/images/car.svg'
];
foreach ($icons as $key => $value) {
$list->push(ArrayData::create([
'ID' => $key,
'Title' => $key,
'Image' => $value
]));
}
return $list;
}