Пример #1
0
    /**
     * Return a newly created pormRender instance with the given name.
     *
     * @param string                    $name       Module name.
     * @param Zikula_AbstractController $controller Controller.
     * @param string                    $className  Optionally instanciate a child of Zikula_Form_View.
     *
     * @return Form_View The newly created Form_View instance.
     */
    public static function newForm($name, Zikula_AbstractController $controller = null, $className=null)
    {
        $serviceManager = $controller->getServiceManager();
        if ($className && !class_exists($className)) {
            throw new RuntimeException(__f('%s does not exist', $className));
        }

        $form = $className ? new $className($serviceManager, $name) : new Zikula_Form_View($serviceManager, $name);
        if ($className && !$form instanceof Zikula_Form_View) {
            throw new RuntimeException(__f('%s is not an instance of Zikula_Form_View', $className));
        }

        $form->setEntityManager($controller->getEntityManager());

        if ($controller) {
            $form->setController($controller);
            $form->assign('controller', $controller);
        } else {
            LogUtil::log(__('FormUtil::newForm should also include the Zikula_AbstractController as the second argument to enable hooks to work.'), Zikula_AbstractErrorHandler::NOTICE);
        }

        return $form;
    }