2013-12-12 16:01:41 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-02-11 19:14:03 +01:00
|
|
|
namespace Propel\Bundle\PropelBundle\Form;
|
2013-12-12 16:01:41 +01:00
|
|
|
|
|
|
|
use Symfony\Component\Form\AbstractExtension;
|
2016-02-17 18:54:32 +01:00
|
|
|
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
|
|
|
|
use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
|
|
|
|
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
|
2013-12-12 16:01:41 +01:00
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
2016-02-17 18:54:32 +01:00
|
|
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
2013-12-12 16:01:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the Propel form extension, which loads the Propel functionality.
|
|
|
|
*
|
|
|
|
* @author Joseph Rouff <rouffj@gmail.com>
|
|
|
|
*/
|
|
|
|
class PropelExtension extends AbstractExtension
|
|
|
|
{
|
2016-02-17 18:54:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var PropertyAccessorInterface
|
|
|
|
*/
|
|
|
|
protected $propertyAccessor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ChoiceListFactoryInterface
|
|
|
|
*/
|
|
|
|
protected $choiceListFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PropelExtension constructor.
|
|
|
|
*
|
|
|
|
* @param PropertyAccessorInterface|null $propertyAccessor
|
|
|
|
* @param ChoiceListFactoryInterface|null $choiceListFactory
|
|
|
|
*/
|
|
|
|
public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null)
|
|
|
|
{
|
|
|
|
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
|
|
|
|
$this->choiceListFactory = $choiceListFactory ?: new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor);
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:01:41 +01:00
|
|
|
protected function loadTypes()
|
|
|
|
{
|
|
|
|
return array(
|
2016-02-17 18:54:32 +01:00
|
|
|
new Type\ModelType($this->propertyAccessor, $this->choiceListFactory),
|
2013-12-12 16:01:41 +01:00
|
|
|
new Type\TranslationCollectionType(),
|
|
|
|
new Type\TranslationType()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function loadTypeGuesser()
|
|
|
|
{
|
|
|
|
return new TypeGuesser();
|
|
|
|
}
|
|
|
|
}
|