Prechádzať zdrojové kódy

[Form] moved the template context creation to the Form class

Moving the template context creation makes sense and allows for simpler code for the end user:

Before:

        return array('post' => $post, 'form' => $this->get('form.factory')->createTemplateContext($form));

After:

        return array('post' => $post, 'form' => $form->getContext());
Fabien Potencier 14 rokov pred
rodič
commit
49dc836521

+ 6 - 0
src/Symfony/Component/Form/Form.php

@@ -26,6 +26,7 @@ use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
 use Symfony\Component\Form\DataTransformer\TransformationFailedException;
 use Symfony\Component\Form\DataMapper\DataMapperInterface;
 use Symfony\Component\Form\Validator\FormValidatorInterface;
+use Symfony\Component\Form\TemplateContext;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
@@ -831,6 +832,11 @@ class Form implements \IteratorAggregate, FormInterface
         return $value;
     }
 
+    public function getContext()
+    {
+        return TemplateContext::create($this);
+    }
+
     /**
      * Reverse transforms a value if a normalization transformer is set.
      *

+ 0 - 6
src/Symfony/Component/Form/FormFactory.php

@@ -17,7 +17,6 @@ use Symfony\Component\Form\Type\Guesser\TypeGuesserInterface;
 use Symfony\Component\Form\Type\Guesser\Guess;
 use Symfony\Component\Form\Exception\FormException;
 use Symfony\Component\Form\Exception\UnexpectedTypeException;
-use Symfony\Component\Form\TemplateContext;
 
 class FormFactory implements FormFactoryInterface
 {
@@ -138,11 +137,6 @@ class FormFactory implements FormFactoryInterface
         return $this->createBuilderForProperty($class, $property, $options)->getForm();
     }
 
-    public function createTemplateContext(FormInterface $form)
-    {
-        return TemplateContext::create($form);
-    }
-
     /**
      * Executes a closure for each guesser and returns the best guess from the
      * return values

+ 0 - 4
src/Symfony/Component/Form/FormFactoryInterface.php

@@ -11,8 +11,6 @@
 
 namespace Symfony\Component\Form;
 
-use Symfony\Component\Form\FormInterface;
-
 interface FormFactoryInterface
 {
     function createBuilder($type, $name = null, array $options = array());
@@ -22,6 +20,4 @@ interface FormFactoryInterface
     function create($type, $name = null, array $options = array());
 
     function createForProperty($class, $property, array $options = array());
-
-    function createTemplateContext(FormInterface $form);
 }

+ 2 - 0
src/Symfony/Component/Form/FormInterface.php

@@ -118,4 +118,6 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
     function getRoot();
 
     function isRoot();
+
+    function getContext();
 }