MDL-75414 mod_data: Fix error when displaying fields in single view

This is a regression from MDL-75146, when the manager class was created.
The field class was not found in the Single view, because the field.class.php
file was not included (so the base class was used in all the cases for this
view). That's why the image field was displaying only the image name instead
of building the <img element or the URLs were displaying only the text, instead
of creating a link for them.
This commit is contained in:
Sara Arjona 2022-08-10 11:38:17 +02:00
parent 35b993b694
commit 9acdb178c7
3 changed files with 18 additions and 6 deletions

View File

@ -228,10 +228,13 @@ class manager {
public function get_field(stdClass $fieldrecord): data_field_base {
$filepath = "{$this->path}/field/{$fieldrecord->type}/field.class.php";
$classname = "data_field_{$fieldrecord->type}";
if (!file_exists($filepath) || !class_exists($classname)) {
if (!file_exists($filepath)) {
return new data_field_base($fieldrecord, $this->instance, $this->cm);
}
require_once($filepath);
if (!class_exists($classname)) {
return new data_field_base($fieldrecord, $this->instance, $this->cm);
}
$newfield = new $classname($fieldrecord, $this->instance, $this->cm);
return $newfield;
}

View File

@ -21,6 +21,10 @@
// //
///////////////////////////////////////////////////////////////////////////
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot.'/lib/filelib.php');
require_once($CFG->dirroot.'/repository/lib.php');

View File

@ -28,6 +28,7 @@ Feature: Users can view and search database entries
| database | type | name | description |
| data1 | text | Test field name | Test field description |
| data1 | text | Test field 2 name | Test field 2 description |
| data1 | url | Test field 3 name | Test field 3 description |
And the following "mod_data > templates" exist:
| database | name |
| data1 | singletemplate |
@ -37,19 +38,23 @@ Feature: Users can view and search database entries
| data1 | rsstemplate |
@javascript
Scenario: Students can add view, list and search entries
Scenario: Students can view, list and search entries
Given the following "mod_data > entries" exist:
| database | Test field name | Test field 2 name |
| data1 | Student entry 1 | |
| data1 | Student entry 2 | |
| data1 | Student entry 3 | |
| database | Test field name | Test field 2 name | Test field 3 name |
| data1 | Student entry 1 | | https://moodledev.io |
| data1 | Student entry 2 | | |
| data1 | Student entry 3 | | |
When I log in as "student1"
And I am on the "Test database name" "data activity" page
Then I should see "Student entry 1"
# Confirm that the URL field is displayed as a link.
And "https://moodledev.io" "link" should exist
And I should see "Student entry 2"
And I should see "Student entry 3"
And I select "Single view" from the "jump" singleselect
And I should see "Student entry 1"
# Confirm that the URL field is displayed as a link.
And "https://moodledev.io" "link" should exist
And I should not see "Student entry 2"
And "2" "link" should exist
And "3" "link" should exist