diff --git a/lib/classes/StudipController.php b/lib/classes/StudipController.php index f99511c543dac3fecd66072365a758ed03866db8..f749bd0d602f1d37ccac7f7bac72c731c5c7e795 100644 --- a/lib/classes/StudipController.php +++ b/lib/classes/StudipController.php @@ -585,7 +585,8 @@ abstract class StudipController extends Trails\Controller public function render_form(\Studip\Forms\Form $form) { - $this->render_text($form->render()); + \NotificationCenter::postNotification('FormWillRender', $form); + $this->render_template($form->getTemplate(), $this->layout); } /** diff --git a/lib/classes/forms/Form.php b/lib/classes/forms/Form.php index a734e6fa6c0b0b4686a06d70e09c282d9376e7f0..0148c9ccb81dc2a48a6763260aae3aaf5461b370 100644 --- a/lib/classes/forms/Form.php +++ b/lib/classes/forms/Form.php @@ -2,6 +2,8 @@ namespace Studip\Forms; +use Flexi\Template; + class Form extends Part { @@ -495,12 +497,20 @@ class Form extends Part * @return string * @throws \Flexi\TemplateNotFoundException */ - public function render() + public function render(string|Template $layout = null) { \NotificationCenter::postNotification('FormWillRender', $this); + return $this->getTemplate()->render([], $layout); + } + + /** + * Returns the template used for this form populated with this form object. + */ + public function getTemplate(): Template + { $template = $GLOBALS['template_factory']->open('forms/form'); $template->form = $this; - return $template->render(); + return $template; } /**