Permalink
Browse files

class Propel\PropelBundle\Model\Form\BaseAbstractType

  • Loading branch information...
1 parent 6ce5c3a commit a7af5d92d9c5f99c6f9e1224e1388de6dd66d3cb @redexp redexp committed Nov 9, 2012
Showing with 62 additions and 33 deletions.
  1. +61 −0 Model/Form/BaseAbstractType.php
  2. +1 −33 Resources/skeleton/FormType.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Propel\PropelBundle\Model\Form;
+
+use Symfony\Component\Form\AbstractType;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
+
+abstract class BaseAbstractType extends AbstractType
+{
+ private $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,9 +2,8 @@
namespace ##NAMESPACE##;
-use Symfony\Component\Form\AbstractType;
+use Propel\PropelBundle\Model\Form\BaseAbstractType;
use Symfony\Component\Form\FormBuilderInterface;
-use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class ##CLASS## extends AbstractType
{
@@ -13,41 +12,10 @@ class ##CLASS## extends AbstractType
'name' => '##TYPE_NAME##',
);
- public function setOption($name, $value)
- {
- $this->options[$name] = $value;
- }
-
- public function getOption($name)
- {
- return $this->options[$name];
- }
-
- public function getOptions()
- {
- return $this->options;
- }
-
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{##BUILD_CODE##
}
-
- /**
- * {@inheritdoc}
- */
- public function setDefaultOptions(OptionsResolverInterface $resolver)
- {
- $resolver->setDefaults($this->options);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getName()
- {
- return $this->getOption('name');
- }
}

0 comments on commit a7af5d9

Please sign in to comment.