Label not replaced with correct value in prototype from admin sonata package collection field

My collection is made of this type

<?php namespace Gustaw\AdminBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class AttributeValueType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('value') ->add('translations', 'a2lix_translations'); } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Gustaw\AdminBundle\Entity\AttributeValue', 'label' => false, )); } public function getName() { return 'attribute_value_type'; } } 

And this is my form

 public function configureFormFields(FormMapper $formMapper) { $formMapper->with('General') ->add('name', null, array('required' => true)) ->add('translations', 'a2lix_translations', array( 'by_reference' => false, 'fields' => array( 'name' => array() ) )) ->add('custom', null, array( 'required' => false, )) ->add('category', 'entity', array( 'required' => true, 'class' => 'GustawAdminBundle:Category', 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('c') ->orderBy('c.root', 'ASC') ->addOrderBy('c.lft', 'ASC'); },)) ->end() ->with('Values') //->add('values', 'sonata_type_collection') ->add('notcustomvalues', 'collection', array( 'type' => new AttributeValueType(), 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'label' => false, 'required' => false, )) ->end(); } 

The problem is adding new items to the collection. Each individual AttributeValueType attribute gets the label "__name__label__ *" when I do not want to have a label for this field, as I set it to false.

I tried setting "prototype_name", hoping that this would change something, only to make things worse.

The only ideas that came to my mind:

1st - create a custom untagged theme only for this collection 2nd - change base.js in SonataAdminBundle

2nd is obviously not a good option, so I only stay with the first one.

Question: are there any other options that I have?

+4
source share
1 answer

Try adding: 'options' => array (label => 'Some Label');

Like this:

  ->add('notcustomvalues', 'collection', array( 'type' => new AttributeValueType(), 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false, 'label' => false, 'required' => false, 'options' => array( 'label' => 'Some Label' ), )) 
+1
source

Source: https://habr.com/ru/post/1484966/


All Articles