<p dir="auto">I'm having some difficulties to do a custom rendering for expanded choices. I'm using an entity type wich is ordering entities by a relation table, and for each different relation I have to do a group of chexkboxes, with another one at the top allowing to select all or none of the group.</p>
<p dir="auto">My issue is that I can't do the correlation between the form views and choice views. So I think it's really complicated to do custom rendering on expanded choices.</p>
<p dir="auto">I'm suggesting to pass the ChoiceView as a var for each choice subForm so that when iterating on the choice formview we can get access to the choice view data, giving more information to be able to render custom stuffs (when the original data is an object).</p>
<p dir="auto">When using <code class="notranslate">"expanded" =&gt; true</code> on a <code class="notranslate">choice</code> field that contains groups, the default form theme simply renders all radio buttons/checkboxes sequentially, without headings or any other indication of the group structure (at least under Twig).</p>
<p dir="auto">From what I can tell, this issue stems from the fact that the choices in an expanded choice field are written directly from the <code class="notranslate">FormView</code>'s <code class="notranslate">choices</code> variable, which is structured into groups. By contrast, expanded choice fields are represented using a series of checkbox/radio button fields, which are treated as children of the choice field - the problem being that the children are not arranged in any hierarchical structure.</p>
<p dir="auto">The <code class="notranslate">FormView</code> for an expanded choice field does still have a <code class="notranslate">choices</code> variable like that of a collapsed choice field, but currently there is no effective way to match up the <code class="notranslate">ChoiceView</code> object with the corresponding child <code class="notranslate">FormView</code> in the template, so rendering the fields from the <code class="notranslate">choices</code> variable as with a collapsed choice field is not a viable option.</p>