Ceci est non testé et simple de me lire l'API Symfony docs for that widget. Vous devrez étendre la classe sfWidgetFormSelectRadio
, l'appeler quelque chose comme myWidgetFormSelectRadio
et le coller dans lib/widget/myWidgetFormSelectRadio.class.php
dans votre projet.
substituez la méthode formatChoices()
comme ceci:
class myWidgetFormSelectRadio extends sfWidgetFormSelectRadio
{
protected function formatChoices($name, $value, $choices, $attributes)
{
$inputs = array();
foreach ($choices as $key => $option)
{
$baseAttributes = array(
'name' => substr($name, 0, -2),
'type' => 'radio',
'value' => self::escapeOnce($key),
'id' => $id = $this->generateId($name, self::escapeOnce($key)),
);
if (strval($key) == strval($value === false ? 0 : $value))
{
$baseAttributes['checked'] = 'checked';
}
$inputs[$id] = array(
'input' =>
$this->renderTag('input', array_merge($baseAttributes, $attributes))
. $this->renderTag('img', array('src' => self::escapeOnce($key))),
'label' => $this->renderContentTag('label', self::escapeOnce($option), array('for' => $id)),
);
}
return call_user_func($this->getOption('formatter'), $this, $inputs);
}
}
donc vous êtes essentiellement annexant la balise img
à l'entrée. Dans la méthode configure()
de votre formulaire, vous devrez passer de sfWidgetFormSelectRadio
à myWidgetFormSelectRadio
pour utiliser le nouveau widget. Faites-moi savoir si cela fonctionne ;-)
Oh ça marche après quelques modifications! Merci! – user198729
Content de l'entendre! Si c'est celui qui a vraiment fonctionné pour vous, vous pourriez vouloir augmenter votre taux de réponse un peu (de 53%) et accepter cette réponse ... ;-) – richsage