فهرست منبع

Updated ModelAutocompleteType::buildForm() to use any attr options set for this widget
Removed span5 default class from attr option and updated tests

caponica 10 سال پیش
والد
کامیت
f3f9b41b0f
2فایلهای تغییر یافته به همراه4 افزوده شده و 2 حذف شده
  1. 2 1
      Form/Type/ModelAutocompleteType.php
  2. 2 1
      Tests/Form/Type/ModelAutocompleteTypeTest.php

+ 2 - 1
Form/Type/ModelAutocompleteType.php

@@ -34,7 +34,7 @@ class ModelAutocompleteType extends AbstractType
     {
         $builder->addViewTransformer(new ModelToIdPropertyTransformer($options['model_manager'], $options['class'], $options['property'], $options['multiple'], $options['to_string_callback']), true);
 
-        $builder->add('title', 'text', array('attr'=>array('class'=>'span5'), 'property_path' => '[labels][0]'));
+        $builder->add('title', 'text', array('attr'=>$options['attr'], 'property_path' => '[labels][0]'));
         $builder->add('identifiers', 'collection', array('type'=>'hidden', 'allow_add' => true, 'allow_delete' => true));
 
         $builder->setAttribute('property', $options['property']);
@@ -74,6 +74,7 @@ class ModelAutocompleteType extends AbstractType
     public function setDefaultOptions(OptionsResolverInterface $resolver)
     {
         $resolver->setDefaults(array(
+            'attr'                            => array(),
             'compound'                        => true,
             'model_manager'                   => null,
             'class'                           => null,

+ 2 - 1
Tests/Form/Type/ModelAutocompleteTypeTest.php

@@ -13,7 +13,7 @@ namespace Sonata\AdminBundle\Tests\Form\Type;
 
 use Sonata\AdminBundle\Form\Type\ModelAutocompleteType;
 
-use Symfony\Component\Form\Tests\Extension\Core\Type\TypeTestCase;
+use Symfony\Component\Form\Test\TypeTestCase;
 use Symfony\Component\OptionsResolver\OptionsResolver;
 
 class ModelAutocompleteTypeTest extends TypeTestCase
@@ -28,6 +28,7 @@ class ModelAutocompleteTypeTest extends TypeTestCase
 
         $options = $optionResolver->resolve(array('model_manager' => $modelManager, 'class' => 'Foo', 'property'=>'bar'));
 
+        $this->assertEquals(array(), $options['attr']);
         $this->assertTrue($options['compound']);
         $this->assertInstanceOf('Sonata\AdminBundle\Model\ModelManagerInterface', $options['model_manager']);
         $this->assertEquals($modelManager, $options['model_manager']);