Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Field controller abstract class

Copyright: 2018 Toni Barbera <toni@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 283 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

field_controller:: (16 methods):
  __construct()
  create()
  parse_value()
  config_form_validation()
  get()
  set()
  delete()
  save()
  to_record()
  get_category()
  get_configdata_property()
  get_handler()
  prepare_for_config_form()
  get_formatted_name()
  supports_course_grouping()
  course_grouping_format_values()


Class: field_controller  - X-Ref

Base class for custom fields controllers

This class is a wrapper around the persistent field class that allows to define the field
configuration

Custom field plugins must define a class
\{pluginname}\field_controller extends \core_customfield\field_controller

__construct(int $id = 0, \stdClass $record = null)   X-Ref
Constructor.

param: int $id
param: \stdClass|null $record

create(int $id, \stdClass $record = null, category_controller $category = null)   X-Ref
Creates an instance of field_controller

Parameters $id, $record and $category can complement each other but not conflict.
If $id is not specified, categoryid must be present either in $record or in $category.
If $id is not specified, type must be present in $record

No DB queries are performed if both $record and $category are specified.

param: int $id
param: \stdClass|null $record
param: category_controller|null $category
return: field_controller will return the instance of the class from the customfield element plugin

parse_value(string $value)   X-Ref
Perform pre-processing of field values, for example those that originate from an external source (e.g. upload course tool)

Override in plugin classes as necessary

param: string $value
return: mixed

config_form_validation(array $data, $files = array()   X-Ref
Validate the data on the field configuration form

Plugins can override it

param: array $data from the add/edit profile field form
param: array $files
return: array associative array of error messages

get(string $property)   X-Ref
Persistent getter parser.

param: string $property
return: mixed

set($property, $value)   X-Ref
Persistent setter parser.

param: string $property
param: mixed $value
return: field

delete()   X-Ref
Delete a field and all associated data

Plugins may override it if it is necessary to delete related data (such as files)

Not that the delete() method from data_controller is not called here.

return: bool

save()   X-Ref
Save or update the persistent class to database.

return: void

to_record()   X-Ref
Persistent to_record parser.

return: \stdClass

get_category()   X-Ref
Get the category associated with this field

return: category_controller

get_configdata_property(string $property)   X-Ref
Get configdata property.

param: string $property name of the property
return: mixed

get_handler()   X-Ref
Returns a handler for this field

return: handler

prepare_for_config_form(\stdClass $formdata)   X-Ref
Prepare the field data to set in the configuration form

Plugin can override if some preprocessing required for editor or filemanager fields

param: \stdClass $formdata

get_formatted_name()   X-Ref
Returns the field name formatted according to configuration context.

return: string

supports_course_grouping()   X-Ref
Does this custom field type support being used as part of the block_myoverview
custom field grouping?

return: bool

course_grouping_format_values($values)   X-Ref
If this field supports course filtering, then this function needs overriding to
return the formatted values for this.

param: array $values the used values that need grouping
return: array