Symfony: set custom data attribute on child form for use in twig template
<p>I have the following setup. 
- A Day Entity
- A Day form which has its own fields</p>

<p>To the Day form I like to add a calculated 'total' value that is based on six Day attributes. I have already successfully created a class that does so. So the main question is: <strong>how to link the calculated data to each Day form</strong>.</p>

<p>I show below only the necessary code, so if you miss something, its not shown.</p>

<p>DayEntity is default, with a bunch of fields.</p>

<p>DayType form:</p>

<pre><code>    class DayType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder
                -&gt;add('field');
        // etc, bunch of fields

        // Here I want to add a calculated field. How to do it?
        // The result is retrieved from my service, with a function: calculateTotal($day);
        }
    }

I have already a service which does the necessary computation:

public function calculateTotal(Day $day)
{
    // Some magic here ;-)

    return $returnDateInterval;
}  
</code></pre>

<p>In Twig I like to do something like:</p>

<pre><code>{{ dayform.vars.data.calculatedTotal|date('H:i') }}
// or
{{ dayform.calculatedTotal|date('H:i') }}
</code></pre>