Description
$builder->add('setting', 'checkbox', array(
'label' => 'user.profile_edit.setting.' . $setting,
'required' => false,
'value' => true,
'mapped' => false,
));
When only using this attributes, the checkbox is not checked. When adding the 'checked' value to this array, an error occurs that this parameter is not allowed. I changed my default twig template to fix the problem.
{# core checkbox #}
{% block checkbox_widget %}
{% spaceless %}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
{% endspaceless %}
{% endblock checkbox_widget %}
{# new checkbox #}
{% block checkbox_widget %}
{% spaceless %}
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if value == true %} checked="checked"{% endif %} />
{% endspaceless %}
{% endblock checkbox_widget %}