Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

(no description)

File Size: 328 lines (12 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: question_handler  - X-Ref

Question handler for custom fields.

create(int $itemid = 0)   X-Ref
Creates the custom field handler and returns a singleton.
Itemid is always zero as the custom fields are the same
for every question across the system.

return: \qbank_customfields\customfield\question_handler
param: int $itemid Always zero.

reset_caches()   X-Ref
Run reset code after unit tests to reset the singleton usage.


can_configure()   X-Ref
The current user can configure custom fields on this component.

return: bool true if the current can configure custom fields, false otherwise

can_edit(field_controller $field, int $instanceid = 0)   X-Ref
The current user can edit custom fields for the given question.

return: bool true if the current can edit custom fields, false otherwise
param: field_controller $field
param: int $instanceid id of the question to test edit permission

can_view(field_controller $field, int $instanceid)   X-Ref
The current user can view custom fields for the given question.

return: bool true if the current can edit custom fields, false otherwise
param: field_controller $field
param: int $instanceid id of the question to test edit permission

can_view_type(field_controller $field, \context $context)   X-Ref
Determine if the current user can view custom field in their given context.
This determines if the user can see the field at all not just the field for
a particular instance.
Used primarily in showing or not the field in the question bank table.

return: bool true if the current can edit custom fields, false otherwise.
param: field_controller $field The field trying to be viewed.
param: context $context The context the field is being displayed in.

set_parent_context(\context $context)   X-Ref
Sets parent context for the question.

This may be needed when question is being created, there is no question context but we need to check capabilities

param: \context $context

get_parent_context()   X-Ref
Returns the parent context for the question.

return: \context

get_configuration_context()   X-Ref
Context that should be used for new categories created by this handler.

return: \context the context for configuration

get_configuration_url()   X-Ref
URL for configuration page for the fields for the question custom fields.

return: \moodle_url The URL to configure custom fields for this component

get_instance_context(int $instanceid = 0)   X-Ref
Returns the context for the data associated with the given instanceid.

return: \context the context for the given record
param: int $instanceid id of the record to get the context for

get_field_data(\core_customfield\field_controller $field, int $instanceid)   X-Ref
Given a field and instance id get all the filed data.

return: \core_customfield\data_controller The fetched data.
param: field_controller $field The field to get the data for.
param: int $instanceid The instance id to get the data for.

get_categories_fields_data(int $instanceid)   X-Ref
For a given instance id (question id) get the categories and the
fields with any data. Return an array of categories containing an
array of field names and values that is ready to be passed to a renderer.

return: array $cfdata The fetched data
param: int $instanceid The instance id to get the data for.

display_custom_field_table(object $fielddata)   X-Ref
Get the custom data for the given field
and render HTML ready for display in question table.

return: string The HTML to display in the table column.
param: object $fielddata The field data used for display.

display_custom_categories_fields(array $catfielddata)   X-Ref
Render the custom field category and filed data as HTML ready for display.

return: string The HTML to display.
param: array $catfielddata Array of categories and field names and values.

config_form_definition(\MoodleQuickForm $mform)   X-Ref
Add custom controls to the field configuration form that will be saved.

param: \MoodleQuickForm $mform The form to add the custom fields to.

restore_instance_data_from_backup(\restore_task $task, array $data)   X-Ref
Creates or updates the question custom field data when restoring from a backup.

param: \restore_task $task
param: array $data