The formatter is used to render the whole form, what you need is to change the rendering of one of the widgets.
The sfwidgetFormDoctrineChoice
has an option renderer
which takes a formatter as an argument. The one that you need is the sfWidgetFormSelectCheckbox
. What I would do is:
create your own class which will extend the
sfWidgetFormSelectCheckbox
class. E.g.class sfWidgetFormMySelectWithThumbs extends sfWidgetFormSelectCheckbox { }
Extend the
configure
function so it takes another option which will hold an array of your thumbnails.public function configure($options = array(), $arguments = array()) { parent::configure($options, $arguments); $this->addOption('thumbnails', array()); }
Change the
formatChoices
function so it adds the image in front of the checkbox (you can copy and modify the originalformatChoices
function).... $sources = $this->getOption('thumbnails'); ... $inputs[$id] = array( 'input' => sprintf('| %s | %s', $this->renderTag('img', array('src' => $sources[$key])), $this->renderTag('input', array_merge($baseAttributes, $attributes)) ), 'label' => $this->renderContentTag('label', self::escapeOnce($option), array('for' => $id)), );
Use the formatter class in your widget:
$this->setWidget('bulkUploadVideos', new sfWidgetFormDoctrineChoice(array( ... 'renderer' => new sfWidgetFormMySelectWithThumbs(array('thumbnails' => $thumbanils)) ) ));
Of course you need to retrieve the list of thumbnails as an array where the array keys are the same as the id's used for values for the checkboxes, but that shouldn't be an issue.