Renderer Refactoring » History » Version 9
Philipp Gröbelbauer, 12.06.2024 12:00
1 | 1 | Philipp Gröbelbauer | h1. Renderer Refactoring |
---|---|---|---|
2 | |||
3 | 8 | Philipp Gröbelbauer | {{toc}} |
4 | 7 | Philipp Gröbelbauer | |
5 | 1 | Philipp Gröbelbauer | Branch: https://git.math.uzh.ch/typo3/qfq/-/tree/F17252_Renderer_Refactoring |
6 | |||
7 | h2. Motivation |
||
8 | 2 | Philipp Gröbelbauer | |
9 | 1 | Philipp Gröbelbauer | To achieve a more modern look and feel, QFQ Forms should support Bootstrap 5 in addition to the previously used Bootstrap 3. |
10 | However, implementing this functionality into the current codebase while still practicing "clean code" is not possible. |
||
11 | Therefore the current code is being refactored to support future expansion. |
||
12 | |||
13 | h2. Concept |
||
14 | 2 | Philipp Gröbelbauer | |
15 | 1 | Philipp Gröbelbauer | Previously, preparation and rendering of the form with all its form elements was handled in AbstractBuildForm.php and BuildFormBootstrap.php. |
16 | The new concept introduces many new classes, making the code much more modular. |
||
17 | Most notably: *Separating Configuration and Rendering of Form and FormElements* ! |
||
18 | By doing this, new Renderer Classes can be implemented in the future, which use the same AbstractFormElement objects to render the element in a different way (e.g. Bootstrap 5). |
||
19 | |||
20 | 4 | Philipp Gröbelbauer | h3. Class diagram |
21 | 1 | Philipp Gröbelbauer | |
22 | 4 | Philipp Gröbelbauer | See the class diagram below: |
23 | |||
24 | 1 | Philipp Gröbelbauer | !renderer_class_diagram_update_2024.drawio.png! |
25 | 4 | Philipp Gröbelbauer | |
26 | h3. Sequence Diagram Form and FormElement Instantiation |
||
27 | |||
28 | tbd |
||
29 | |||
30 | h3. Sequence Diagram Rendering |
||
31 | |||
32 | The diagram below describes the rendering process. |
||
33 | |||
34 | * The BaseRenderer (or any specific implementation of it) takes the previously instantiated Form object that describes all aspects of the form that is to be rendered. |
||
35 | |||
36 | 6 | Philipp Gröbelbauer | !renderer_sequence_diagram_update_2024.drawio.png! |
37 | 9 | Philipp Gröbelbauer | |
38 | |||
39 | h2. Dev Guide |
||
40 | |||
41 | This section should answer common questions on how to use the refactored code and how to expand upon it. |
||
42 | |||
43 | h3. Adding a New Form Element |
||
44 | |||
45 | This chapter describes how new form elements can be added into QFQ in the new model. |
||
46 | In this example we are assuming a new FormElement "Chat" should be implemented in QFQ. |
||
47 | Follow these steps: |
||
48 | |||
49 | # Create a new class ChatFormElement in the folder Core>Form>FormElement. |
||
50 | This class needs to extend AbstractFormElement and should call the parent's construct method when instantiated, as seen in the screenshot below. |
||
51 | If the form element you want to introduce is a ContainerFormElement, then extend ContainerFormElement instead of AbstractFormElement! |
||
52 | |||
53 | !clipboard-202406121148-aqvlm.png! |
||
54 | |||
55 | # Add a new CASE block to the SWITCH statement in FeFactory.php. |
||
56 | This way the factory will return an object of your newly created class when needed. |
||
57 | It is best to add a new constant in Constants.php that defines the new FE type. In this example the constant FE_TYPE_CHAT is simply defined as 'chat'. |
||
58 | |||
59 | !clipboard-202406121152-vlscn.png! |
||
60 | |||
61 | # Create a class ChatRenderer in the folder Core>Renderer>FormElement>Base |
||
62 | This class is supposed to render a chat element completely independent of the used CSS Framework. |
||
63 | In practice, this class might stay empty. |
||
64 | |||
65 | !clipboard-202406121158-y2gwo.png! |