-
Improvement
-
Resolution: Fixed
-
Major
-
4.1
-
MOODLE_401_STABLE
-
MOODLE_402_STABLE
-
MDL-75498-master -
-
3
-
HQ Sprint 0.4 Database
One of the main problems of the mod_data is that teachers are forced to use the templates to use the activity. Even using the default templates, if the teacher adds a new field all templates must be reset or edit to include the new field. This situation is even worst when the teacher uses a preset because the only way of including a new field is by adding it manually in all templates (because resetting them will wipe also the applied template).
While templates are just plain HTML with a few tags (instead a more advanced mustache file or equivalent) there is no way to add the new fields directly into the template. However, it will be doable to add a new tag ##otherfields## that includes all the fields that are not present in the template in a simple list.
Furthermore, if a teacher changes the name or the description of a field, the [[FIELD]] tag will be replaced but if she wrote the name of the field in some template it won't be converted. This situation is easily solved if there were a [FIELD#name] and [FIELD#description] that loads the field description directly into the template.
For example, imagine the current image gallery singletemplate.html could look like this:
<div class="imagegallery-single"> |
<div class="d-flex"> |
<h3 class="card-title">[[title]]</h3> |
<div class="ml-auto">##actionsmenu##</div> |
</div>
|
<div class="imagegallery-single-body"> |
<div class="row"> |
<div class="col col-3 col-md-1"><strong>Author</strong></div> |
<div class="col">##userpicture## ##user##</div> |
</div>
|
<div class="row"> |
<div class="col col-3 col-md-1"><strong>Date</strong></div> |
<div class="col">##timeadded##</div> |
</div>
|
<div class="row singleentry-caption"> <div class="col col-3 col-md-1"><strong>[[description#name]]</strong></div> <div class="col">[[description]]</div> |
</div>
|
<div class="row singleentry-image"> |
<div class="col">[[image]]</div> |
</div>
|
<div class="row singleentry-otherfields"> |
<div class="col">##otherfields##</div> |
</div>
|
</div>
|
</div>
|
When the teacher:
- Adds a new field (example value This is my new field value)
- And another new field My location (example value 41.391205, 2.163873 )
The resulting HTML could be:
<div class="imagegallery-single"> |
<div class="d-flex"> |
<h3 class="card-title">[[title]]</h3> |
<div class="ml-auto"><span class="actrion-menu">....</span></div> |
</div>
|
<div class="imagegallery-single-body"> |
<div class="row"> |
<div class="col col-3 col-md-1"><strong>Author</strong></div> |
<div class="col"><img class="userpix" .... /></div> |
</div>
|
<div class="row"> |
<div class="col col-3 col-md-1"><strong>Date</strong></div> |
<div class="col">16th of August 2022</div> |
</div>
|
<div class="row singleentry-caption"> <div class="col col-3 col-md-1"><strong>Description</strong></div> <div class="col">The image description value</div> |
</div>
|
<div class="row singleentry-image"> |
<div class="col"><img src="the image itself"/></div> |
</div>
|
<div class="row singleentry-otherfields"> |
<div class="col"> |
<div class="field-04 data-field-name">New field</div> |
<div class="field-04 data-field-value">This is my new field value</div> |
<div class="field-05 data-field-name">My location</div> |
<div class="field-05 data-field-value"><a href="...">41.391205, 2.163873</a> |
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
This won't solve all the database problems but it will make the presets more reusable.
Some technical details
1) The data_append_new_field_to_templates method should do nothing if the ##otherfields## is present. By all means, the ##otherfields## is an advanced version of appending a new field.
2) mod/data/edit.php should also take into account the existence of ##otherfields## to autogenerate all the necessary form inputs.
3) Both asearchtemplate and addentrytemplate should be compatible with all the new tags even if they have a different rendering logic.
4) About the asearchtermplate, the parsing is not refactored yet. For now, the new tags will be added to the current code while the refactoring issue is not yet done.
- caused a regression
-
MDL-77177 mod/data/classes/template.php php81 problem
- Closed
-
MOBILE-4247 Add ##otherfields##, [[FIELD#name]] and [[FIELD#description]] tags to the database templates in App
- Closed
- has been marked as being related by
-
MDL-77015 HTML in database field management page escaped in an unexpected way
- Closed
- is blocked by
-
MDL-75234 Use default templates in mod_data if the templates are not created.
- Closed