22
33namespace Opifer \EavBundle \Form \Type ;
44
5+ use Doctrine \ORM \EntityRepository ;
56use Symfony \Component \Form \AbstractType ;
7+ use Symfony \Component \Form \Extension \Core \Type \IntegerType ;
8+ use Symfony \Component \Form \Extension \Core \Type \TextType ;
69use Symfony \Component \Form \FormBuilderInterface ;
7- use Symfony \Component \OptionsResolver \OptionsResolverInterface ;
810use Symfony \Component \Form \FormEvent ;
911use Symfony \Component \Form \FormEvents ;
10- use Doctrine \ ORM \ EntityRepository ;
12+ use Symfony \ Component \ OptionsResolver \ OptionsResolver ;
1113
1214class AttributeType extends AbstractType
1315{
14- /**
15- * @var string
16- */
16+ /** @var string */
1717 protected $ attributeClass ;
1818
19- /**
20- * @var string
21- */
19+ /** @var string */
2220 protected $ templateClass ;
2321
22+ /** @var OptionType */
2423 protected $ optionType ;
2524
26-
2725 /**
2826 * Constructor
2927 *
30- * @param OptionType $optionType
31- * @param string $attributeClass
32- * @param string $templateClass
28+ * @param OptionType $optionType
29+ * @param string $attributeClass
30+ * @param string $templateClass
3331 */
3432 public function __construct (OptionType $ optionType , $ attributeClass , $ templateClass )
3533 {
@@ -50,7 +48,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5048 'placeholder ' => 'form.value_type.placeholder ' ,
5149 'help_text ' => 'form.value_type.help_text '
5250 ]
53- ])->add ('displayName ' , ' text ' , [
51+ ])->add ('displayName ' , TextType::class , [
5452 'label ' => 'attribute.display_name ' ,
5553 'attr ' => [
5654 'class ' => 'slugify ' ,
@@ -60,19 +58,19 @@ public function buildForm(FormBuilderInterface $builder, array $options)
6058 'help_text ' => 'form.display_name.help_text ' ,
6159 'widget_col ' => 6
6260 ]
63- ])->add ('name ' , ' text ' , [
61+ ])->add ('name ' , TextType::class , [
6462 'label ' => 'attribute.name ' ,
6563 'attr ' => [
6664 'class ' => 'slugify-target- ' . $ builder ->getName (),
6765 'placeholder ' => 'form.name.placeholder ' ,
6866 'help_text ' => 'form.name.help_text ' ,
6967 'widget_col ' => 6
7068 ]
71- ])->add ('description ' , ' text ' , [
69+ ])->add ('description ' , TextType::class , [
7270 'required ' => false ,
7371 'label ' => 'attribute.description ' ,
7472 'attr ' => [ 'help_text ' => 'form.description.help_text ' ]
75- ])->add ('sort ' , ' integer ' , [
73+ ])->add ('sort ' , IntegerType::class , [
7674 'label ' => 'attribute.sort ' ,
7775 'attr ' => [ 'help_text ' => 'form.sort.help_text ' , 'widget_col ' => 2 ],
7876 'empty_data ' => 0
@@ -91,44 +89,46 @@ public function buildForm(FormBuilderInterface $builder, array $options)
9189 }
9290
9391 if ($ attribute && $ attribute ->getValueType () == 'nested ' ) {
94- $ form ->add (
95- 'allowedTemplates ' ,
96- 'entity ' ,
97- [
98- 'class ' => $ this ->templateClass ,
99- 'property ' => 'displayName ' ,
100- 'query_builder ' => function (EntityRepository $ er ) {
101- return $ er ->createQueryBuilder ('t ' )
102- ->orderBy ('t.displayName ' , 'ASC ' );
103- },
104- 'by_reference ' => false ,
105- 'expanded ' => true ,
106- 'multiple ' => true ,
107- 'label ' => 'attribute.allowed_templates ' ,
108- 'attr ' => ['help_text ' => 'form.allowed_templates.help_text ' ]
109- ]
110- );
92+ $ form ->add ('allowedTemplates ' , 'entity ' , [
93+ 'class ' => $ this ->templateClass ,
94+ 'property ' => 'displayName ' ,
95+ 'query_builder ' => function (EntityRepository $ er ) {
96+ return $ er ->createQueryBuilder ('t ' )
97+ ->orderBy ('t.displayName ' , 'ASC ' );
98+ },
99+ 'by_reference ' => false ,
100+ 'expanded ' => true ,
101+ 'multiple ' => true ,
102+ 'label ' => 'attribute.allowed_templates ' ,
103+ 'attr ' => ['help_text ' => 'form.allowed_templates.help_text ' ]
104+ ]);
111105 }
112106 });
113107 }
114108
115-
116109 /**
117110 * {@inheritDoc}
118111 */
119- public function setDefaultOptions ( OptionsResolverInterface $ resolver )
112+ public function configureOptions ( OptionsResolver $ resolver )
120113 {
121- $ resolver ->setDefaults (array (
114+ $ resolver ->setDefaults ([
122115 'data_class ' => $ this ->attributeClass ,
123- ) );
116+ ] );
124117 }
125118
119+ /**
120+ * @deprecated
121+ */
122+ public function getName ()
123+ {
124+ return $ this ->getBlockPrefix ();
125+ }
126126
127127 /**
128128 * {@inheritDoc}
129129 */
130- public function getName ()
130+ public function getBlockPrefix ()
131131 {
132132 return 'eav_attribute ' ;
133133 }
134- }
134+ }
0 commit comments