This commit is contained in:
Jun Pataleta 2024-03-08 08:00:41 +08:00
commit 3278ce7aba
No known key found for this signature in database
GPG key ID: F83510526D99E2C7
1147 changed files with 2621 additions and 2617 deletions

View file

@ -54,7 +54,7 @@ class api {
* If ($adddefaults): All fieldids are present, some data_controller objects may have 'id', some not.
* If (!$adddefaults): Only fieldids with data are present, all data_controller objects have 'id'.
*/
public static function get_instance_fields_data(array $fields, int $instanceid, bool $adddefaults = true) : array {
public static function get_instance_fields_data(array $fields, int $instanceid, bool $adddefaults = true): array {
return self::get_instances_fields_data($fields, [$instanceid], $adddefaults)[$instanceid];
}
@ -69,7 +69,7 @@ class api {
* If (!$adddefaults): All instanceids are present but only fieldids with data are present, all
* data_controller objects have 'id'.
*/
public static function get_instances_fields_data(array $fields, array $instanceids, bool $adddefaults = true) : array {
public static function get_instances_fields_data(array $fields, array $instanceids, bool $adddefaults = true): array {
global $DB;
// Create the results array where instances and fields order is the same as in the input arrays.
@ -230,7 +230,7 @@ class api {
*
* @param field_controller $field
*/
public static function delete_field_configuration(field_controller $field) : bool {
public static function delete_field_configuration(field_controller $field): bool {
$event = field_deleted::create_from_object($field);
get_file_storage()->delete_area_files($field->get_handler()->get_configuration_context()->id, 'core_customfield',
'description', $field->get('id'));
@ -246,7 +246,7 @@ class api {
* @param bool $editable
* @return inplace_editable
*/
public static function get_category_inplace_editable(category_controller $category, bool $editable = true) : inplace_editable {
public static function get_category_inplace_editable(category_controller $category, bool $editable = true): inplace_editable {
return new inplace_editable('core_customfield',
'category',
$category->get('id'),
@ -318,7 +318,7 @@ class api {
* @param category_controller $category
* @return bool
*/
public static function delete_category(category_controller $category) : bool {
public static function delete_category(category_controller $category): bool {
$event = category_deleted::create_from_object($category);
// Delete all fields.
@ -339,7 +339,7 @@ class api {
* @param int $itemid
* @return category_controller[]
*/
public static function get_categories_with_fields(string $component, string $area, int $itemid) : array {
public static function get_categories_with_fields(string $component, string $area, int $itemid): array {
global $DB;
$categories = [];
@ -397,7 +397,7 @@ class api {
* @param field_controller $field
* @return \stdClass
*/
public static function prepare_field_for_config_form(field_controller $field) : \stdClass {
public static function prepare_field_for_config_form(field_controller $field): \stdClass {
if ($field->get('id')) {
$formdata = $field->to_record();
$formdata->configdata = $field->get('configdata');

View file

@ -46,7 +46,7 @@ class category extends persistent {
*
* @return array
*/
protected static function define_properties() : array {
protected static function define_properties(): array {
return array(
'name' => [
'type' => PARAM_TEXT,

View file

@ -77,7 +77,7 @@ class category_controller {
* @throws \moodle_exception
* @throws \coding_exception
*/
public static function create(int $id, \stdClass $record = null, handler $handler = null) : category_controller {
public static function create(int $id, \stdClass $record = null, handler $handler = null): category_controller {
global $DB;
if ($id && $record) {
// This warning really should be in persistent as well.
@ -180,7 +180,7 @@ class category_controller {
*
* @return handler
*/
public function get_handler() : handler {
public function get_handler(): handler {
if ($this->handler === null) {
$this->handler = handler::get_handler($this->get('component'), $this->get('area'), $this->get('itemid'));
}
@ -224,7 +224,7 @@ class category_controller {
*
* @return string
*/
public function get_formatted_name() : string {
public function get_formatted_name(): string {
$context = $this->get_handler()->get_configuration_context();
return format_string($this->get('name'), true, ['context' => $context]);
}

View file

@ -47,7 +47,7 @@ class data extends persistent {
*
* @return array
*/
protected static function define_properties() : array {
protected static function define_properties(): array {
return array(
'fieldid' => [
'type' => PARAM_INT,

View file

@ -83,7 +83,7 @@ abstract class data_controller {
* @throws \coding_exception
* @throws \moodle_exception
*/
public static function create(int $id, \stdClass $record = null, field_controller $field = null) : data_controller {
public static function create(int $id, \stdClass $record = null, field_controller $field = null): data_controller {
global $DB;
if ($id && $record) {
// This warning really should be in persistent as well.
@ -123,7 +123,7 @@ abstract class data_controller {
*
* @return string
*/
public function get_form_element_name() : string {
public function get_form_element_name(): string {
return 'customfield_' . $this->get_field()->get('shortname');
}
@ -161,7 +161,7 @@ abstract class data_controller {
*
* @return string
*/
abstract public function datafield() : string;
abstract public function datafield(): string;
/**
* Delete data. Element can override it if related information needs to be deleted as well (such as files)
@ -186,7 +186,7 @@ abstract class data_controller {
*
* @return field_controller
*/
public function get_field() : field_controller {
public function get_field(): field_controller {
return $this->field;
}
@ -224,7 +224,7 @@ abstract class data_controller {
* @param mixed $value
* @return bool
*/
protected function is_empty($value) : bool {
protected function is_empty($value): bool {
if ($this->datafield() === 'value' || $this->datafield() === 'charvalue' || $this->datafield() === 'shortcharvalue') {
return '' . $value === '';
}
@ -237,7 +237,7 @@ abstract class data_controller {
* @param mixed $value
* @return bool
*/
protected function is_unique($value) : bool {
protected function is_unique($value): bool {
global $DB;
// Ensure the "value" datafield can be safely compared across all databases.
@ -262,7 +262,7 @@ abstract class data_controller {
* @param array $files
* @return array array of errors
*/
public function instance_form_validation(array $data, array $files) : array {
public function instance_form_validation(array $data, array $files): array {
$errors = [];
$elementname = $this->get_form_element_name();
if ($this->get_field()->get_configdata_property('uniquevalues') == 1) {
@ -288,7 +288,7 @@ abstract class data_controller {
*
* @return string
*/
public function display() : string {
public function display(): string {
global $PAGE;
$output = $PAGE->get_renderer('core_customfield');
return $output->render(new field_data($this));
@ -299,7 +299,7 @@ abstract class data_controller {
*
* @return mixed
*/
public abstract function get_default_value();
abstract public function get_default_value();
/**
* Returns the value as it is stored in the database or default value if data record is not present
@ -318,7 +318,7 @@ abstract class data_controller {
*
* @return \context
*/
public function get_context() : \context {
public function get_context(): \context {
if ($this->get('contextid')) {
return \context::instance_by_id($this->get('contextid'));
} else if ($this->get('instanceid')) {
@ -334,7 +334,7 @@ abstract class data_controller {
*
* @param \MoodleQuickForm $mform
*/
public abstract function instance_form_definition(\MoodleQuickForm $mform);
abstract public function instance_form_definition(\MoodleQuickForm $mform);
/**
* Returns value in a human-readable format or default value if data record is not present

View file

@ -53,7 +53,7 @@ class category_created extends \core\event\base {
* @param category_controller $category
* @return category_created
*/
public static function create_from_object(category_controller $category) : category_created {
public static function create_from_object(category_controller $category): category_created {
$eventparams = [
'objectid' => $category->get('id'),
'context' => $category->get_handler()->get_configuration_context(),

View file

@ -53,7 +53,7 @@ class category_deleted extends \core\event\base {
* @param category_controller $category
* @return category_deleted
*/
public static function create_from_object(category_controller $category) : category_deleted {
public static function create_from_object(category_controller $category): category_deleted {
$eventparams = [
'objectid' => $category->get('id'),
'context' => $category->get_handler()->get_configuration_context(),

View file

@ -53,7 +53,7 @@ class category_updated extends \core\event\base {
* @param category_controller $category
* @return category_updated
*/
public static function create_from_object(category_controller $category) : category_updated {
public static function create_from_object(category_controller $category): category_updated {
$eventparams = [
'objectid' => $category->get('id'),
'context' => $category->get_handler()->get_configuration_context(),

View file

@ -53,7 +53,7 @@ class field_created extends \core\event\base {
* @param field_controller $field
* @return field_created
*/
public static function create_from_object(field_controller $field) : field_created {
public static function create_from_object(field_controller $field): field_created {
$eventparams = [
'objectid' => $field->get('id'),
'context' => $field->get_handler()->get_configuration_context(),

View file

@ -53,7 +53,7 @@ class field_deleted extends \core\event\base {
* @param field_controller $field
* @return field_deleted
*/
public static function create_from_object(field_controller $field) : field_deleted {
public static function create_from_object(field_controller $field): field_deleted {
$eventparams = [
'objectid' => $field->get('id'),
'context' => $field->get_handler()->get_configuration_context(),

View file

@ -53,7 +53,7 @@ class field_updated extends \core\event\base {
* @param field_controller $field
* @return field_updated
*/
public static function create_from_object(field_controller $field) : field_updated {
public static function create_from_object(field_controller $field): field_updated {
$eventparams = [
'objectid' => $field->get('id'),
'context' => $field->get_handler()->get_configuration_context(),

View file

@ -47,7 +47,7 @@ class field extends persistent {
*
* @return array
*/
protected static function define_properties() : array {
protected static function define_properties(): array {
return array(
'name' => [
'type' => PARAM_TEXT,
@ -91,7 +91,7 @@ class field extends persistent {
*
* @return array
*/
protected function get_configdata() : array {
protected function get_configdata(): array {
return json_decode($this->raw_get('configdata') ?? '', true) ?? array();
}
}

View file

@ -81,7 +81,7 @@ abstract class field_controller {
* @throws \coding_exception
* @throws \moodle_exception
*/
public static function create(int $id, \stdClass $record = null, category_controller $category = null) : field_controller {
public static function create(int $id, \stdClass $record = null, category_controller $category = null): field_controller {
global $DB;
if ($id && $record) {
// This warning really should be in persistent as well.
@ -144,7 +144,7 @@ abstract class field_controller {
* @param array $files
* @return array associative array of error messages
*/
public function config_form_validation(array $data, $files = array()) : array {
public function config_form_validation(array $data, $files = array()): array {
return array();
}
@ -179,7 +179,7 @@ abstract class field_controller {
*
* @return bool
*/
public function delete() : bool {
public function delete(): bool {
global $DB;
$DB->delete_records('customfield_data', ['fieldid' => $this->get('id')]);
return $this->field->delete();
@ -208,7 +208,7 @@ abstract class field_controller {
*
* @return category_controller
*/
public final function get_category() : category_controller {
final public function get_category(): category_controller {
return $this->category;
}
@ -231,7 +231,7 @@ abstract class field_controller {
*
* @return handler
*/
public final function get_handler() : handler {
final public function get_handler(): handler {
return $this->get_category()->get_handler();
}
@ -250,14 +250,14 @@ abstract class field_controller {
*
* @param \MoodleQuickForm $mform
*/
public abstract function config_form_definition(\MoodleQuickForm $mform);
abstract public function config_form_definition(\MoodleQuickForm $mform);
/**
* Returns the field name formatted according to configuration context.
*
* @return string
*/
public function get_formatted_name() : string {
public function get_formatted_name(): string {
$context = $this->get_handler()->get_configuration_context();
return format_string($this->get('name'), true, ['context' => $context]);
}

View file

@ -83,7 +83,7 @@ abstract class handler {
*
* @param int $itemid
*/
protected final function __construct(int $itemid = 0) {
final protected function __construct(int $itemid = 0) {
if (!preg_match('|^(\w+_[\w_]+)\\\\customfield\\\\([\w_]+)_handler$|', static::class, $matches)) {
throw new \coding_exception('Handler class name must have format: <PLUGIN>\\customfield\\<AREA>_handler');
}
@ -100,7 +100,7 @@ abstract class handler {
* @param int $itemid
* @return handler
*/
public static function create(int $itemid = 0) : handler {
public static function create(int $itemid = 0): handler {
return new static($itemid);
}
@ -112,7 +112,7 @@ abstract class handler {
* @param int $itemid item id if the area uses them (usually not used)
* @return handler
*/
public static function get_handler(string $component, string $area, int $itemid = 0) : handler {
public static function get_handler(string $component, string $area, int $itemid = 0): handler {
$classname = $component . '\\customfield\\' . $area . '_handler';
if (class_exists($classname) && is_subclass_of($classname, self::class)) {
return $classname::create($itemid);
@ -126,7 +126,7 @@ abstract class handler {
*
* @return string
*/
public function get_component() : string {
public function get_component(): string {
return $this->component;
}
@ -135,7 +135,7 @@ abstract class handler {
*
* @return string
*/
public function get_area() : string {
public function get_area(): string {
return $this->area;
}
@ -144,14 +144,14 @@ abstract class handler {
*
* @return \context
*/
abstract public function get_configuration_context() : \context;
abstract public function get_configuration_context(): \context;
/**
* URL for configuration of the fields on this handler.
*
* @return \moodle_url
*/
abstract public function get_configuration_url() : \moodle_url;
abstract public function get_configuration_url(): \moodle_url;
/**
* Context that should be used for data stored for the given record
@ -159,14 +159,14 @@ abstract class handler {
* @param int $instanceid id of the instance or 0 if the instance is being created
* @return \context
*/
abstract public function get_instance_context(int $instanceid = 0) : \context;
abstract public function get_instance_context(int $instanceid = 0): \context;
/**
* Get itemid
*
* @return int|null
*/
public function get_itemid() : int {
public function get_itemid(): int {
return $this->itemid;
}
@ -175,7 +175,7 @@ abstract class handler {
*
* @return bool
*/
public function uses_categories() : bool {
public function uses_categories(): bool {
return true;
}
@ -185,7 +185,7 @@ abstract class handler {
* @param int $suffix
* @return string
*/
protected function generate_category_name($suffix = 0) : string {
protected function generate_category_name($suffix = 0): string {
if ($suffix) {
return get_string('otherfieldsn', 'core_customfield', $suffix);
} else {
@ -199,7 +199,7 @@ abstract class handler {
* @param string $name name of the category, null to generate automatically
* @return int id of the new category
*/
public function create_category(string $name = null) : int {
public function create_category(string $name = null): int {
global $DB;
$params = ['component' => $this->get_component(), 'area' => $this->get_area(), 'itemid' => $this->get_itemid()];
@ -225,7 +225,7 @@ abstract class handler {
* @return category_controller
* @throws \moodle_exception
*/
protected function validate_category(category_controller $category) : category_controller {
protected function validate_category(category_controller $category): category_controller {
$categories = $this->get_categories_with_fields();
if (!array_key_exists($category->get('id'), $categories)) {
throw new \moodle_exception('categorynotfound', 'core_customfield');
@ -240,7 +240,7 @@ abstract class handler {
* @return field_controller
* @throws \moodle_exception
*/
protected function validate_field(field_controller $field) : field_controller {
protected function validate_field(field_controller $field): field_controller {
if (!array_key_exists($field->get('categoryid'), $this->get_categories_with_fields())) {
throw new \moodle_exception('fieldnotfound', 'core_customfield');
}
@ -282,7 +282,7 @@ abstract class handler {
* @param category_controller $category
* @return bool
*/
public function delete_category(category_controller $category) : bool {
public function delete_category(category_controller $category): bool {
$category = $this->validate_category($category);
$result = api::delete_category($category);
$this->clear_configuration_cache();
@ -306,7 +306,7 @@ abstract class handler {
* @param field_controller $field
* @return bool
*/
public function delete_field_configuration(field_controller $field) : bool {
public function delete_field_configuration(field_controller $field): bool {
$field = $this->validate_field($field);
$result = api::delete_field_configuration($field);
$this->clear_configuration_cache();
@ -331,7 +331,7 @@ abstract class handler {
*
* @return bool
*/
abstract public function can_configure() : bool;
abstract public function can_configure(): bool;
/**
* The current user can edit given custom fields on the given instance
@ -344,7 +344,7 @@ abstract class handler {
* @param int $instanceid id of the instance or 0 if the instance is being created
* @return bool
*/
abstract public function can_edit(field_controller $field, int $instanceid = 0) : bool;
abstract public function can_edit(field_controller $field, int $instanceid = 0): bool;
/**
* The current user can view the value of the custom field for a given custom field and instance
@ -358,7 +358,7 @@ abstract class handler {
* @param int $instanceid
* @return bool
*/
abstract public function can_view(field_controller $field, int $instanceid) : bool;
abstract public function can_view(field_controller $field, int $instanceid): bool;
/**
* Returns the custom field values for an individual instance
@ -373,7 +373,7 @@ abstract class handler {
* some data_controller objects may have 'id', some not
* In the last case data_controller::get_value() and export_value() functions will return default values.
*/
public function get_instance_data(int $instanceid, bool $returnall = false) : array {
public function get_instance_data(int $instanceid, bool $returnall = false): array {
$fields = $returnall ? $this->get_fields() : $this->get_visible_fields($instanceid);
return api::get_instance_fields_data($fields, $instanceid);
}
@ -391,7 +391,7 @@ abstract class handler {
* All instanceids and all fieldids are present, some data_controller objects may have 'id', some not.
* In the last case data_controller::get_value() and export_value() functions will return default values.
*/
public function get_instances_data(array $instanceids, bool $returnall = false) : array {
public function get_instances_data(array $instanceids, bool $returnall = false): array {
$result = api::get_instances_fields_data($this->get_fields(), $instanceids);
if (!$returnall) {
@ -417,7 +417,7 @@ abstract class handler {
* @param bool $returnall
* @return \core_customfield\output\field_data[]
*/
public function export_instance_data(int $instanceid, bool $returnall = false) : array {
public function export_instance_data(int $instanceid, bool $returnall = false): array {
return array_map(function($d) {
return new field_data($d);
}, $this->get_instance_data($instanceid, $returnall));
@ -434,7 +434,7 @@ abstract class handler {
* @param bool $returnall
* @return stdClass
*/
public function export_instance_data_object(int $instanceid, bool $returnall = false) : stdClass {
public function export_instance_data_object(int $instanceid, bool $returnall = false): stdClass {
$rv = new stdClass();
foreach ($this->export_instance_data($instanceid, $returnall) as $d) {
$rv->{$d->get_shortname()} = $d->get_value();
@ -449,7 +449,7 @@ abstract class handler {
* @param data_controller[] $fieldsdata
* @return string
*/
public function display_custom_fields_data(array $fieldsdata) : string {
public function display_custom_fields_data(array $fieldsdata): string {
global $PAGE;
$output = $PAGE->get_renderer('core_customfield');
$content = '';
@ -466,7 +466,7 @@ abstract class handler {
*
* @return category_controller[]
*/
public function get_categories_with_fields() : array {
public function get_categories_with_fields(): array {
if ($this->categories === null) {
$this->categories = api::get_categories_with_fields($this->get_component(), $this->get_area(), $this->get_itemid());
}
@ -493,7 +493,7 @@ abstract class handler {
* @param int $instanceid
* @return bool
*/
protected function can_backup(field_controller $field, int $instanceid) : bool {
protected function can_backup(field_controller $field, int $instanceid): bool {
return $this->can_view($field, $instanceid) || $this->can_edit($field, $instanceid);
}
@ -534,7 +534,7 @@ abstract class handler {
* @param int $instanceid
* @return array
*/
public function get_instance_data_for_backup(int $instanceid) : array {
public function get_instance_data_for_backup(int $instanceid): array {
$finalfields = [];
$data = $this->get_instance_data($instanceid, true);
foreach ($data as $d) {
@ -700,7 +700,7 @@ abstract class handler {
*
* @return array
*/
public function get_available_field_types() :array {
public function get_available_field_types(): array {
return api::get_available_field_types();
}
@ -712,7 +712,7 @@ abstract class handler {
*
* @return array
*/
public function get_description_text_options() : array {
public function get_description_text_options(): array {
global $CFG;
require_once($CFG->libdir.'/formslib.php');
return [
@ -761,7 +761,7 @@ abstract class handler {
*
* @return field_controller[]
*/
public function get_fields() : array {
public function get_fields(): array {
$categories = $this->get_categories_with_fields();
$fields = [];
foreach ($categories as $category) {
@ -778,7 +778,7 @@ abstract class handler {
* @param int $instanceid
* @return field_controller[]
*/
protected function get_visible_fields(int $instanceid) : array {
protected function get_visible_fields(int $instanceid): array {
$handler = $this;
return array_filter($this->get_fields(),
function($field) use($handler, $instanceid) {
@ -793,7 +793,7 @@ abstract class handler {
* @param int $instanceid
* @return field_controller[]
*/
public function get_editable_fields(int $instanceid) : array {
public function get_editable_fields(int $instanceid): array {
$handler = $this;
return array_filter($this->get_fields(),
function($field) use($handler, $instanceid) {

View file

@ -63,7 +63,7 @@ class field_data implements \renderable, \templatable {
*
* @return string
*/
public function get_type() : string {
public function get_type(): string {
return $this->data->get_field()->get('type');
}
@ -72,7 +72,7 @@ class field_data implements \renderable, \templatable {
*
* @return string
*/
public function get_shortname() : string {
public function get_shortname(): string {
return $this->data->get_field()->get('shortname');
}
@ -81,7 +81,7 @@ class field_data implements \renderable, \templatable {
*
* @return string
*/
public function get_name() : string {
public function get_name(): string {
return $this->data->get_field()->get_formatted_name();
}
@ -90,7 +90,7 @@ class field_data implements \renderable, \templatable {
*
* @return data_controller
*/
public function get_data_controller() : data_controller {
public function get_data_controller(): data_controller {
return $this->data;
}

View file

@ -60,7 +60,7 @@ class provider implements
* @param collection $collection a reference to the collection to use to store the metadata.
* @return collection the updated collection of metadata items.
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {
$collection->add_database_table(
'customfield_data',
[
@ -103,7 +103,7 @@ class provider implements
* @return contextlist
*/
public static function get_customfields_data_contexts(string $component, string $area,
string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = []) : contextlist {
string $itemidstest = 'IS NOT NULL', string $instanceidstest = 'IS NOT NULL', array $params = []): contextlist {
$sql = "SELECT d.contextid FROM {customfield_category} c
JOIN {customfield_field} f ON f.categoryid = c.id
@ -130,7 +130,7 @@ class provider implements
* @return contextlist
*/
public static function get_customfields_configuration_contexts(string $component, string $area,
string $itemidstest = 'IS NOT NULL', array $params = []) : contextlist {
string $itemidstest = 'IS NOT NULL', array $params = []): contextlist {
$sql = "SELECT c.contextid FROM {customfield_category} c
WHERE c.component = :cfcomponent AND c.area = :cfarea AND c.itemid $itemidstest";
@ -331,7 +331,7 @@ class provider implements
* @return array
* @throws \coding_exception
*/
protected static function get_params(string $component, string $area, array $params) : array {
protected static function get_params(string $component, string $area, array $params): array {
if (!empty($params) && (array_keys($params) === range(0, count($params) - 1))) {
// Argument $params is not an associative array.
throw new \coding_exception('Argument $params must be an associative array!');

View file

@ -42,7 +42,7 @@ class data_controller extends \core_customfield\data_controller {
* Return the name of the field where the information is stored
* @return string
*/
public function datafield() : string {
public function datafield(): string {
return 'intvalue';
}

View file

@ -59,7 +59,7 @@ class field_controller extends \core_customfield\field_controller {
* @param array $files
* @return array associative array of error messages
*/
public function config_form_validation(array $data, $files = array()) : array {
public function config_form_validation(array $data, $files = array()): array {
$errors = parent::config_form_validation($data, $files);
if ($data['configdata']['uniquevalues']) {

View file

@ -43,7 +43,7 @@ class provider implements \core_privacy\local\metadata\null_provider, customfiel
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}

View file

@ -68,7 +68,7 @@ class plugin_test extends \advanced_testcase {
* Get generator
* @return core_customfield_generator
*/
protected function get_generator() : core_customfield_generator {
protected function get_generator(): core_customfield_generator {
return $this->getDataGenerator()->get_plugin_generator('core_customfield');
}

View file

@ -41,7 +41,7 @@ class data_controller extends \core_customfield\data_controller {
* Return the name of the field where the information is stored
* @return string
*/
public function datafield() : string {
public function datafield(): string {
return 'intvalue';
}
@ -90,7 +90,7 @@ class data_controller extends \core_customfield\data_controller {
* @param array $files
* @return array
*/
public function instance_form_validation(array $data, array $files) : array {
public function instance_form_validation(array $data, array $files): array {
$errors = parent::instance_form_validation($data, $files);
$elementname = $this->get_form_element_name();

View file

@ -46,7 +46,7 @@ class field_controller extends \core_customfield\field_controller {
* @param array $files
* @return array associative array of error messages
*/
public function config_form_validation(array $data, $files = array()) : array {
public function config_form_validation(array $data, $files = array()): array {
$errors = array();
// Make sure the start year is not greater than the end year.

View file

@ -43,7 +43,7 @@ class provider implements \core_privacy\local\metadata\null_provider, customfiel
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}

View file

@ -65,7 +65,7 @@ class plugin_test extends \advanced_testcase {
* Get generator
* @return core_customfield_generator
*/
protected function get_generator() : core_customfield_generator {
protected function get_generator(): core_customfield_generator {
return $this->getDataGenerator()->get_plugin_generator('core_customfield');
}
@ -169,7 +169,7 @@ class plugin_test extends \advanced_testcase {
*
* @return array
*/
public function parse_value_provider() : array {
public function parse_value_provider(): array {
return [
// Valid times.
['2019-10-01', strtotime('2019-10-01')],

View file

@ -39,7 +39,7 @@ class data_controller extends \core_customfield\data_controller {
* Return the name of the field where the information is stored
* @return string
*/
public function datafield() : string {
public function datafield(): string {
return 'intvalue';
}
@ -93,7 +93,7 @@ class data_controller extends \core_customfield\data_controller {
* @param array $files
* @return array
*/
public function instance_form_validation(array $data, array $files) : array {
public function instance_form_validation(array $data, array $files): array {
$errors = parent::instance_form_validation($data, $files);
if ($this->get_field()->get_configdata_property('required')) {
// Standard required rule does not work on select element.

View file

@ -77,7 +77,7 @@ class field_controller extends \core_customfield\field_controller {
* @param array $files
* @return array associative array of error messages
*/
public function config_form_validation(array $data, $files = array()) : array {
public function config_form_validation(array $data, $files = array()): array {
$options = preg_split("/\s*\n\s*/", trim($data['configdata']['options']));
$errors = [];
if (!$options || count($options) < 2) {

View file

@ -42,7 +42,7 @@ class provider implements \core_privacy\local\metadata\null_provider, customfiel
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}

View file

@ -69,7 +69,7 @@ class plugin_test extends \advanced_testcase {
* Get generator
* @return core_customfield_generator
*/
protected function get_generator() : core_customfield_generator {
protected function get_generator(): core_customfield_generator {
return $this->getDataGenerator()->get_plugin_generator('core_customfield');
}
@ -155,7 +155,7 @@ class plugin_test extends \advanced_testcase {
*
* @return array
*/
public function parse_value_provider() : array {
public function parse_value_provider(): array {
return [
['Red', 1],
['Blue', 2],

View file

@ -41,7 +41,7 @@ class data_controller extends \core_customfield\data_controller {
* Return the name of the field where the information is stored
* @return string
*/
public function datafield() : string {
public function datafield(): string {
return 'charvalue';
}
@ -72,7 +72,7 @@ class data_controller extends \core_customfield\data_controller {
* @param array $files
* @return array
*/
public function instance_form_validation(array $data, array $files) : array {
public function instance_form_validation(array $data, array $files): array {
$errors = parent::instance_form_validation($data, $files);
$maxlength = $this->get_field()->get_configdata_property('maxlength');

View file

@ -95,7 +95,7 @@ class field_controller extends \core_customfield\field_controller {
* @param array $files
* @return array associative array of error messages
*/
public function config_form_validation(array $data, $files = array()) : array {
public function config_form_validation(array $data, $files = array()): array {
global $CFG;
$errors = parent::config_form_validation($data, $files);

View file

@ -42,7 +42,7 @@ class provider implements \core_privacy\local\metadata\null_provider, customfiel
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}

View file

@ -74,7 +74,7 @@ class plugin_test extends \advanced_testcase {
* Get generator
* @return core_customfield_generator
*/
protected function get_generator() : core_customfield_generator {
protected function get_generator(): core_customfield_generator {
return $this->getDataGenerator()->get_plugin_generator('core_customfield');
}

View file

@ -41,7 +41,7 @@ class data_controller extends \core_customfield\data_controller {
* Return the name of the field where the information is stored
* @return string
*/
public function datafield() : string {
public function datafield(): string {
return 'value';
}
@ -61,7 +61,7 @@ class data_controller extends \core_customfield\data_controller {
*
* @return string
*/
public function get_form_element_name() : string {
public function get_form_element_name(): string {
return parent::get_form_element_name() . '_editor';
}

View file

@ -42,7 +42,7 @@ class field_controller extends \core_customfield\field_controller {
/**
* Before delete bulk actions
*/
public function delete() : bool {
public function delete(): bool {
global $DB;
$fs = get_file_storage();

View file

@ -42,7 +42,7 @@ class provider implements \core_privacy\local\metadata\null_provider, customfiel
*
* @return string
*/
public static function get_reason() : string {
public static function get_reason(): string {
return 'privacy:metadata';
}

View file

@ -73,7 +73,7 @@ class plugin_test extends \advanced_testcase {
* Get generator
* @return core_customfield_generator
*/
protected function get_generator() : core_customfield_generator {
protected function get_generator(): core_customfield_generator {
return $this->getDataGenerator()->get_plugin_generator('core_customfield');
}

View file

@ -80,7 +80,7 @@ class core_customfield_generator extends component_generator_base {
* @param array|stdClass $record
* @return field_controller
*/
public function create_field($record) : field_controller {
public function create_field($record): field_controller {
$this->fieldcount++;
$i = $this->fieldcount;
$record = (object) $record;
@ -150,7 +150,7 @@ class core_customfield_generator extends component_generator_base {
* @param mixed $value
* @return \core_customfield\data_controller
*/
public function add_instance_data(field_controller $field, int $instanceid, $value) : \core_customfield\data_controller {
public function add_instance_data(field_controller $field, int $instanceid, $value): \core_customfield\data_controller {
$data = \core_customfield\data_controller::create(0, (object)['instanceid' => $instanceid], $field);
$data->set('contextid', $data->get_context()->id);