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