From 2d2396a7d35b7c3c73f16c52f9fb3ecb56ce76f7 Mon Sep 17 00:00:00 2001 From: Jurian Sluiman Date: Tue, 23 Apr 2013 10:42:36 +0200 Subject: [PATCH] Add FormUtils class to inject plugins into forms --- src/Common/Form/FormUtils.php | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/Common/Form/FormUtils.php diff --git a/src/Common/Form/FormUtils.php b/src/Common/Form/FormUtils.php new file mode 100644 index 0000000..6ca02c3 --- /dev/null +++ b/src/Common/Form/FormUtils.php @@ -0,0 +1,75 @@ + + * @copyright 2013 Jurian Sluiman. + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @link http://soflomo.com + */ + +namespace Soflomo\Common\Form; + +use Zend\Form\Form; +use Zend\ServiceManager\ServiceLocatorInterface; + +use Zend\Filter\FilterChain; +use Zend\Validator\ValidatorChain; + +class FormUtils +{ + public static function injectFormPluginManager(Form $form, ServiceLocatorInterface $sl) + { + $plugins = $sl->get('FormElementManager'); + + $form->getFormFactory()->setFormElementManager($plugins); + } + + public static function injectFilterPluginManager(Form $form, ServiceLocatorInterface $sl) + { + $plugins = $sl->get('FilterManager'); + $chain = new FilterChain; + $chain->setPluginManager($plugins); + + $form->getFormFactory()->getInputFilterFactory()->setDefaultFilterChain($chain); + } + + public static function injectValidatorPluginManager(Form $form, ServiceLocatorInterface $sl) + { + $plugins = $sl->get('ValidatorManager'); + $chain = new FilterChain; + $chain->setPluginManager($plugins); + + $form->getFormFactory()->getInputFilterFactory()->setDefaultFilterChain($chain); + } +} \ No newline at end of file