1111
1212namespace Symfony \Component \Form \Extension \Core \Type ;
1313
14- use Symfony \Component \Form \AbstractType ;
1514use Symfony \Component \Form \FormBuilderInterface ;
1615use Symfony \Component \Form \FormInterface ;
1716use Symfony \Component \Form \FormView ;
2322use Symfony \Component \PropertyAccess \PropertyAccess ;
2423use Symfony \Component \PropertyAccess \PropertyAccessorInterface ;
2524
26- class FormType extends AbstractType
25+ class FormType extends BaseType
2726{
2827 /**
2928 * @var PropertyAccessorInterface
@@ -40,9 +39,10 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null)
4039 */
4140 public function buildForm (FormBuilderInterface $ builder , array $ options )
4241 {
42+ parent ::buildForm ($ builder , $ options );
43+
4344 $ builder
4445 ->setRequired ($ options ['required ' ])
45- ->setDisabled ($ options ['disabled ' ])
4646 ->setErrorBubbling ($ options ['error_bubbling ' ])
4747 ->setEmptyData ($ options ['empty_data ' ])
4848 ->setPropertyPath ($ options ['property_path ' ])
@@ -65,85 +65,34 @@ public function buildForm(FormBuilderInterface $builder, array $options)
6565 */
6666 public function buildView (FormView $ view , FormInterface $ form , array $ options )
6767 {
68+ parent ::buildView ($ view , $ form , $ options );
69+
6870 $ name = $ form ->getName ();
69- $ blockName = $ options ['block_name ' ] ?: $ form ->getName ();
7071 $ readOnly = $ options ['read_only ' ];
71- $ translationDomain = $ options ['translation_domain ' ];
7272
7373 if ($ view ->parent ) {
7474 if ('' === $ name ) {
7575 throw new Exception ('Form node with empty name can be used only as root form node. ' );
7676 }
7777
78- if ('' !== ($ parentFullName = $ view ->parent ->vars ['full_name ' ])) {
79- $ id = sprintf ('%s_%s ' , $ view ->parent ->vars ['id ' ], $ name );
80- $ fullName = sprintf ('%s[%s] ' , $ parentFullName , $ name );
81- $ uniqueBlockPrefix = sprintf ('%s_%s ' , $ view ->parent ->vars ['unique_block_prefix ' ], $ blockName );
82- } else {
83- $ id = $ name ;
84- $ fullName = $ name ;
85- $ uniqueBlockPrefix = '_ ' .$ blockName ;
86- }
87-
8878 // Complex fields are read-only if they themselves or their parents are.
8979 if (!$ readOnly ) {
9080 $ readOnly = $ view ->parent ->vars ['read_only ' ];
9181 }
92-
93- if (!$ translationDomain ) {
94- $ translationDomain = $ view ->parent ->vars ['translation_domain ' ];
95- }
96- } else {
97- $ id = $ name ;
98- $ fullName = $ name ;
99- $ uniqueBlockPrefix = '_ ' .$ blockName ;
100-
101- // Strip leading underscores and digits. These are allowed in
102- // form names, but not in HTML4 ID attributes.
103- // http://www.w3.org/TR/html401/struct/global.html#adef-id
104- $ id = ltrim ($ id , '_0123456789 ' );
105- }
106-
107- $ blockPrefixes = array ();
108- for ($ type = $ form ->getConfig ()->getType (); null !== $ type ; $ type = $ type ->getParent ()) {
109- array_unshift ($ blockPrefixes , $ type ->getName ());
110- }
111- $ blockPrefixes [] = $ uniqueBlockPrefix ;
112-
113- if (!$ translationDomain ) {
114- $ translationDomain = 'messages ' ;
11582 }
11683
11784 $ view ->vars = array_replace ($ view ->vars , array (
118- 'form ' => $ view ,
119- 'id ' => $ id ,
120- 'name ' => $ name ,
121- 'full_name ' => $ fullName ,
122- 'read_only ' => $ readOnly ,
123- 'errors ' => $ form ->getErrors (),
124- 'valid ' => $ form ->isBound () ? $ form ->isValid () : true ,
125- 'value ' => $ form ->getViewData (),
126- 'data ' => $ form ->getNormData (),
127- 'disabled ' => $ form ->isDisabled (),
128- 'required ' => $ form ->isRequired (),
129- 'max_length ' => $ options ['max_length ' ],
130- 'pattern ' => $ options ['pattern ' ],
131- 'size ' => null ,
132- 'label ' => $ options ['label ' ],
133- 'multipart ' => false ,
134- 'attr ' => $ options ['attr ' ],
135- 'label_attr ' => $ options ['label_attr ' ],
136- 'compound ' => $ form ->getConfig ()->getCompound (),
137- 'block_prefixes ' => $ blockPrefixes ,
138- 'unique_block_prefix ' => $ uniqueBlockPrefix ,
139- 'translation_domain ' => $ translationDomain ,
140- // Using the block name here speeds up performance in collection
141- // forms, where each entry has the same full block name.
142- // Including the type is important too, because if rows of a
143- // collection form have different types (dynamically), they should
144- // be rendered differently.
145- // https://github.com/symfony/symfony/issues/5038
146- 'cache_key ' => $ uniqueBlockPrefix .'_ ' .$ form ->getConfig ()->getType ()->getName (),
85+ 'read_only ' => $ readOnly ,
86+ 'errors ' => $ form ->getErrors (),
87+ 'valid ' => $ form ->isBound () ? $ form ->isValid () : true ,
88+ 'value ' => $ form ->getViewData (),
89+ 'data ' => $ form ->getNormData (),
90+ 'required ' => $ form ->isRequired (),
91+ 'max_length ' => $ options ['max_length ' ],
92+ 'pattern ' => $ options ['pattern ' ],
93+ 'size ' => null ,
94+ 'label_attr ' => $ options ['label_attr ' ],
95+ 'compound ' => $ form ->getConfig ()->getCompound (),
14796 ));
14897 }
14998
@@ -169,6 +118,8 @@ public function finishView(FormView $view, FormInterface $form, array $options)
169118 */
170119 public function setDefaultOptions (OptionsResolverInterface $ resolver )
171120 {
121+ parent ::setDefaultOptions ($ resolver );
122+
172123 // Derive "data_class" option from passed "data" object
173124 $ dataClass = function (Options $ options ) {
174125 return isset ($ options ['data ' ]) && is_object ($ options ['data ' ]) ? get_class ($ options ['data ' ]) : null ;
@@ -202,29 +153,23 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
202153 ));
203154
204155 $ resolver ->setDefaults (array (
205- 'block_name ' => null ,
206156 'data_class ' => $ dataClass ,
207157 'empty_data ' => $ emptyData ,
208158 'trim ' => true ,
209159 'required ' => true ,
210160 'read_only ' => false ,
211- 'disabled ' => false ,
212161 'max_length ' => null ,
213162 'pattern ' => null ,
214163 'property_path ' => null ,
215164 'mapped ' => true ,
216165 'by_reference ' => true ,
217166 'error_bubbling ' => $ errorBubbling ,
218- 'label ' => null ,
219- 'attr ' => array (),
220167 'label_attr ' => array (),
221168 'virtual ' => false ,
222169 'compound ' => true ,
223- 'translation_domain ' => null ,
224170 ));
225171
226172 $ resolver ->setAllowedTypes (array (
227- 'attr ' => 'array ' ,
228173 'label_attr ' => 'array ' ,
229174 ));
230175 }
0 commit comments