繁体   English   中英

在sonata管理束集合字段的原型中,标签未被正确的值替换

[英]Label not replaced with correct value in prototype from sonata admin bundle collection field

我的收藏品是这种类型的

<?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';
    }
}

这是我的形式

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();
}

问题是在集合中添加新元素时。 当我不想为此字段添加任何标签时,每个AttributeValueType都会获得一个标签“__name__label__ *”,因为我将其设置为false。

我尝试设置“prototype_name”,希望它会改变一些东西只是为了让它变得更糟。

我想到的唯一想法是:

1st - 为这一个集合创建没有标签的自定义主题第二个 - 在SonataAdminBundle中编辑base.js

第二个显然不是很好的选择,所以我只剩下第一个。

问题是:我还有其他选择吗?

尝试添加:'options'=> array(label =>'Some Label');

像这样:

        ->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'
                ),

        ))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM