Example #1
0
 /**
  * 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->getServiceManager();
     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.'), Zikula_AbstractErrorHandler::NOTICE);
     }
     return $form;
 }