vendor/symfony/form/Extension/DataCollector/Proxy/ResolvedTypeDataCollectorProxy.php line 109

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Form\Extension\DataCollector\Proxy;
  11. use Symfony\Component\Form\Extension\DataCollector\FormDataCollectorInterface;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\Form\FormFactoryInterface;
  14. use Symfony\Component\Form\FormInterface;
  15. use Symfony\Component\Form\FormView;
  16. use Symfony\Component\Form\ResolvedFormTypeInterface;
  17. /**
  18.  * Proxy that invokes a data collector when creating a form and its view.
  19.  *
  20.  * @author Bernhard Schussek <bschussek@gmail.com>
  21.  */
  22. class ResolvedTypeDataCollectorProxy implements ResolvedFormTypeInterface
  23. {
  24.     private $proxiedType;
  25.     private $dataCollector;
  26.     public function __construct(ResolvedFormTypeInterface $proxiedTypeFormDataCollectorInterface $dataCollector)
  27.     {
  28.         $this->proxiedType $proxiedType;
  29.         $this->dataCollector $dataCollector;
  30.     }
  31.     /**
  32.      * {@inheritdoc}
  33.      */
  34.     public function getBlockPrefix()
  35.     {
  36.         return $this->proxiedType->getBlockPrefix();
  37.     }
  38.     /**
  39.      * {@inheritdoc}
  40.      */
  41.     public function getParent()
  42.     {
  43.         return $this->proxiedType->getParent();
  44.     }
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public function getInnerType()
  49.     {
  50.         return $this->proxiedType->getInnerType();
  51.     }
  52.     /**
  53.      * {@inheritdoc}
  54.      */
  55.     public function getTypeExtensions()
  56.     {
  57.         return $this->proxiedType->getTypeExtensions();
  58.     }
  59.     /**
  60.      * {@inheritdoc}
  61.      */
  62.     public function createBuilder(FormFactoryInterface $factorystring $name, array $options = [])
  63.     {
  64.         $builder $this->proxiedType->createBuilder($factory$name$options);
  65.         $builder->setAttribute('data_collector/passed_options'$options);
  66.         $builder->setType($this);
  67.         return $builder;
  68.     }
  69.     /**
  70.      * {@inheritdoc}
  71.      */
  72.     public function createView(FormInterface $form, ?FormView $parent null)
  73.     {
  74.         return $this->proxiedType->createView($form$parent);
  75.     }
  76.     /**
  77.      * {@inheritdoc}
  78.      */
  79.     public function buildForm(FormBuilderInterface $builder, array $options)
  80.     {
  81.         $this->proxiedType->buildForm($builder$options);
  82.     }
  83.     /**
  84.      * {@inheritdoc}
  85.      */
  86.     public function buildView(FormView $viewFormInterface $form, array $options)
  87.     {
  88.         $this->proxiedType->buildView($view$form$options);
  89.     }
  90.     /**
  91.      * {@inheritdoc}
  92.      */
  93.     public function finishView(FormView $viewFormInterface $form, array $options)
  94.     {
  95.         $this->proxiedType->finishView($view$form$options);
  96.         // Remember which view belongs to which form instance, so that we can
  97.         // get the collected data for a view when its form instance is not
  98.         // available (e.g. CSRF token)
  99.         $this->dataCollector->associateFormWithView($form$view);
  100.         // Since the CSRF token is only present in the FormView tree, we also
  101.         // need to check the FormView tree instead of calling isRoot() on the
  102.         // FormInterface tree
  103.         if (null === $view->parent) {
  104.             $this->dataCollector->collectViewVariables($view);
  105.             // Re-assemble data, in case FormView instances were added, for
  106.             // which no FormInterface instances were present (e.g. CSRF token).
  107.             // Since finishView() is called after finishing the views of all
  108.             // children, we can safely assume that information has been
  109.             // collected about the complete form tree.
  110.             $this->dataCollector->buildFinalFormTree($form$view);
  111.         }
  112.     }
  113.     /**
  114.      * {@inheritdoc}
  115.      */
  116.     public function getOptionsResolver()
  117.     {
  118.         return $this->proxiedType->getOptionsResolver();
  119.     }
  120. }