I need to be able to add a CSS class to each individual radio button of my choice field(s). Unfortunately, Symfony2 stuffs expanded choices in a div, which gets any passed in CSS class rather than the buttons themselves.
Here's the default widget theming (in PHP):
<div <?php echo $view['form']->block($form, 'widget_container_attributes') ?>>
<?php foreach ($form as $child): ?>
<?php echo $view['form']->widget($child) ?>
<?php echo $view['form']->label($child) ?>
<?php endforeach ?>
</div>
Here's my div-less version (in twig):
{% block choice_widget_expanded %}
{% for child in form %}
{{ form_widget(child) }}
{{ form_label(child) }}
{% endfor %}
{% endblock %}
With that, how can I pass the CSS class to the actual widget? I'm passing it in like:
{% form_widget(form.blah, { 'attr' : { 'class': 'css-class' } }) %}
In my view, but I'm not sure how to grab it in my widget theme.
I can't not use radio buttons for this, so telling me to switch to a select or checkboxes isn't an option. And I really, really don't want to hard code the radios into my form view if I can help it.
EDIT: I've tried:
{% block choice_widget_expanded %}
{% for child in form %}
<input type="radio" value="{{ child.vars.value }}" {{ block('widget_attributes') }} />
{% endfor %}
{% endblock %}
Yet it still renders a containing div in the source, and passes my CSS class to that div instead of the radio inputs. I know that the theme is 'working' because I had a few exceptions thrown during my fiddling.
EDIT 2: With the suggestion below, I've created my own radio_widget theme:
{% block radio_widget %}
<input type="radio" class="star {split:2}" {{ block('widget_attributes') }} value="{{ value }}" {% if checked == true %}checked="checked"{% endif %} />
{% endblock %}
But, unfortunately, it's not generating the radios with the class I added above. I'm not sure if I need to do some inheritance work.