Permalink
Browse files

Merge pull request #191 from redexp/FormType

added $options field and get() set() methods for it
  • Loading branch information...
2 parents 1dbd438 + 6bac311 commit 1aae1fc96b53ff4e9a62ecd0dced26194d89066e @willdurand willdurand committed Nov 20, 2012
Showing with 68 additions and 21 deletions.
  1. +61 −0 Form/BaseAbstractType.php
  2. +7 −21 Resources/skeleton/FormType.php
View
@@ -0,0 +1,61 @@
+<?php
+
+namespace Propel\PropelBundle\Form;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+abstract class BaseAbstractType extends AbstractType
+{
+ protected $options = array(
+ 'name' => '',
+ );
+
+ function __construct($mergeOptions = null)
+ {
+ if ($mergeOptions) {
+ $this->mergeOptions($mergeOptions);
+ }
+ }
+
+ public function setOption($name, $value)
+ {
+ $this->options[$name] = $value;
+ }
+
+ public function getOption($name)
+ {
+ return $this->options[$name];
+ }
+
+ public function setOptions($options)
+ {
+ $this->options = $options;
+ }
+
+ public function getOptions()
+ {
+ return $this->options;
+ }
+
+ public function mergeOptions($options)
+ {
+ $this->options = array_merge($this->options, $options);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setDefaultOptions(OptionsResolverInterface $resolver)
+ {
+ $resolver->setDefaults($this->options);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return $this->getOption('name');
+ }
+}
@@ -2,34 +2,20 @@
namespace ##NAMESPACE##;
-use Symfony\Component\Form\AbstractType;
+use Propel\PropelBundle\Form\BaseAbstractType;
use Symfony\Component\Form\FormBuilderInterface;
-use Symfony\Component\OptionsResolver\OptionsResolverInterface;
-class ##CLASS## extends AbstractType
+class ##CLASS## extends BaseAbstractType
{
+ protected $options = array(
+ 'data_class' => '##FQCN##',
+ 'name' => '##TYPE_NAME##',
+ );
+
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{##BUILD_CODE##
}
-
- /**
- * {@inheritdoc}
- */
- public function setDefaultOptions(OptionsResolverInterface $resolver)
- {
- $resolver->setDefaults(array(
- 'data_class' => '##FQCN##',
- ));
- }
-
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- return '##TYPE_NAME##';
- }
}

0 comments on commit 1aae1fc

Please sign in to comment.