Merge pull request #191 from redexp/FormType
added $options field and get() set() methods for it
This commit is contained in:
commit
1aae1fc96b
61
Form/BaseAbstractType.php
Normal file
61
Form/BaseAbstractType.php
Normal file
|
@ -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##';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue