簡體   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