Symfony: How to access label form collection Type?

I am creating a bundle for polls in Symfony.
In there i have an Entity Campaign which consists of many Instances of the Entity Block.

I made a FormType called CampaignType which gets an Input added of the Type CollectionType which holds all of the blocks in this campaign as you can see in this code here

class CampaignType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('blocks', CollectionType::class, array(
            'entry_type' => BlockType::class,
            'entry_options' => array('label' => 'test02'),
        ));

        $builder->add('Save', SubmitType::class, array('attr' => array('class' => 'btn btn-success')));
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => Campaign::class
        ));
    }
}

Each Block has a name which i want to display at the view, but when i use {{ form_label(block) }} i get the label ‘test02’ that i used in the codeexample above. In this function i can only access the members of the Campaign but not of the Block. How can i get the data from the Block in there?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *