17
17
namespace mod_cms \customfield ;
18
18
19
19
use core_customfield \{field_controller , handler };
20
+ use mod_cms \local \model \cms ;
20
21
use mod_cms \local \model \cms_types ;
21
22
use mod_cms \local \datasource \userlist ;
22
23
31
32
class cmsuserlist_handler extends handler {
32
33
use cms_restore;
33
34
35
+ /** @var cms The CMS for the fields. */
36
+ public $ cms = null ;
37
+
34
38
/**
35
- * Context that should be used for new categories created by this handler
39
+ * Context that should be used for new categories created by this handler.
36
40
*
37
41
* @return \context
38
42
*/
@@ -41,13 +45,20 @@ public function get_configuration_context(): \context {
41
45
}
42
46
43
47
/**
44
- * Context that should be used for data stored for the given record
48
+ * Context that should be used for data stored for the given record.
49
+ * Uses the activity context.
45
50
*
46
51
* @param int $instanceid id of the instance or 0 if the instance is being created
47
52
* @return \context
48
53
*/
49
54
public function get_instance_context (int $ instanceid = 0 ): \context {
50
- return $ this ->get_configuration_context ();
55
+ if (!is_null ($ this ->cms )) {
56
+ $ modinfo = get_coursemodule_from_instance ('cms ' , $ this ->cms ->get ('id ' ));
57
+ if ($ modinfo ) {
58
+ return \context_module::instance ($ modinfo ->id );
59
+ }
60
+ }
61
+ return \context_system::instance ();
51
62
}
52
63
53
64
/**
@@ -78,11 +89,11 @@ public function can_configure(): bool {
78
89
}
79
90
80
91
/**
81
- * The current user can edit given custom fields on the given instance
92
+ * The current user can edit given custom fields on the given instance.
82
93
*
83
- * Called to filter list of fields displayed on the instance edit form
94
+ * Called to filter list of fields displayed on the instance edit form.
84
95
*
85
- * Capability to edit/create instance is checked separately
96
+ * Capability to edit/create instance is checked separately.
86
97
*
87
98
* @param field_controller $field
88
99
* @param int $instanceid id of the instance or 0 if the instance is being created
@@ -93,7 +104,7 @@ public function can_edit(field_controller $field, int $instanceid = 0): bool {
93
104
}
94
105
95
106
/**
96
- * The current user can view the value of the custom field for a given custom field and instance
107
+ * The current user can view the value of the custom field for a given custom field and instance.
97
108
*
98
109
* Called to filter list of fields returned by methods get_instance_data(), get_instances_data(),
99
110
* export_instance_data(), export_instance_data_object()
0 commit comments