-
Improvement
-
Resolution: Fixed
-
Critical
-
4.5
-
MOODLE_405_STABLE
-
MOODLE_405_STABLE
-
MDL-82571_V2 -
-
3
-
WP Sprint 2024-I3.1 (Clones), WP Sprint 2024-I3.2 (Clones)
Following on from MDL-80858, there are additional requirements for Workplace in this custom field type:
- Add "Display format" setting for the field, describing how it should be displayed. Very often we want to display a particular suffix or prefix, maybe display the fixed number of digits after decimal point. When the value is 15.5, for example, "Price" field will be displayed as "$ 15.50" but the "Duration" field will be displayed as "15.5 hours" and so on. Default value is "%g"
- Add a separate setting "Display when zero". Again, in the example above, for the "Price" it will be the word "Free" but for the "Duration" it would mean that the duration is unknown and the field should be left empty (which means it won't be displayed at all). Default value is "0"
- And finally a separate setting "Display when empty". In the majority of cases it will be empty value, which means do not display but in some cases somebody may want to show "unknown", for example. Default value is empty
- Add tests ensuring that the custom field is displayed using this format in the course listing (i.e. "Avaiable courses" on the front page) and WS core_course_get_courses_by_field returns the field correctly
Requirements:
- The "Display format" should use a placeholder for the value. I would recommend to use the same placeholders the function sprintf takes because they serve most of the use cases. Only admin can change the setting for the custom field so we assume that it is not a problem that it's a little "nerdy".
- Add validation that makes sure that a placeholder is used in the value of the setting "Display format".
- Make sure these settings work with multilang filter, including the case when people enter placeholder several times (one for each language).
- Keep in mind that in
MDL-82715we will need to make all of the settings fields hidden if the "Automatically populated" field type is selected. It is not possible to use a header in "hideIf()" function, therefore the "Input format" and "Display format" are not headers but are actually static fields. For the same reason it may not be possible to display a "required" exclamation mark next to the "Display template" field even though the field is actually required. It is ok to deviate from mockups in such cases - Create a separate method prepare_field_for_display() in the field_controller class that applies the "Display format" and call it from data_controller::export_value. This function will be needed for the follow up tasks
MDL-82715and WP-4863 - we need to be able to hook into into and also call it independently to format bounds of the ranges.
Mockups for all the setting fields: