/** * 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) { $container = $controller->getContainer(); if ($className && !class_exists($className)) { throw new RuntimeException(__f('%s does not exist', $className)); } $form = $className ? new $className($container, $name) : new Zikula_Form_View($container, $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; }
/** * Return a newly created Zikula Form instance with the given name. * * @param string $name Module or plugin name. * @param Zikula_AbstractController $controller Controller. * @param string $className Optionally instanciate a child of Zikula_Form_View. * * @return Zikula_Form_View The newly created Form_View instance. */ public static function newForm($name, Zikula_AbstractController $controller = null, $className = null) { $serviceManager = $controller->getContainer(); if ($className && !class_exists($className)) { throw new RuntimeException(__f('%s does not exist', $className)); } if ($controller instanceof Zikula_Controller_AbstractPlugin) { // for plugins get module name from controller $modinfo = $controller->getModInfo(); $form = $className ? new $className($serviceManager, $modinfo['name'], $name) : new Zikula_Form_View_Plugin($serviceManager, $modinfo['name'], $name); } else { $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.'), \Monolog\Logger::NOTICE); } return $form; }