MDL-57898 core_customfield: coding style fixes

This commit is contained in:
Marina Glancy
2019-01-18 14:28:24 +01:00
parent c1e15d20e0
commit bbf60b1412
45 changed files with 102 additions and 92 deletions
@@ -104,7 +104,7 @@ class course_handler extends \core_customfield\handler {
* @param int $instanceid id of the course to test edit permission
* @return bool true if the current can edit custom fields, false otherwise
*/
public function can_view(field_controller $field, int $instanceid): bool {
public function can_view(field_controller $field, int $instanceid) : bool {
$visibility = $field->get_configdata_property('visibility');
if ($visibility == self::NOTVISIBLE) {
return false;
@@ -146,7 +146,7 @@ class course_handler extends \core_customfield\handler {
*
* @return \context the context for configuration
*/
public function get_configuration_context(): \context {
public function get_configuration_context() : \context {
return \context_system::instance();
}
@@ -155,7 +155,7 @@ class course_handler extends \core_customfield\handler {
*
* @return \moodle_url The URL to configure custom fields for this component
*/
public function get_configuration_url(): \moodle_url {
public function get_configuration_url() : \moodle_url {
return new \moodle_url('/course/customfield.php');
}
@@ -165,7 +165,7 @@ class course_handler extends \core_customfield\handler {
* @param int $instanceid id of the record to get the context for
* @return \context the context for the given record
*/
public function get_instance_context(int $instanceid = 0): \context {
public function get_instance_context(int $instanceid = 0) : \context {
if ($instanceid > 0) {
return \context_course::instance($instanceid);
} else {
@@ -230,7 +230,7 @@ class course_handler extends \core_customfield\handler {
* @param field_controller $field
* @return string page heading
*/
public function setup_edit_page(field_controller $field): string {
public function setup_edit_page(field_controller $field) : string {
global $CFG, $PAGE;
require_once($CFG->libdir.'/adminlib.php');
+2 -2
View File
@@ -205,7 +205,7 @@ class core_course_list_element implements IteratorAggregate {
*
* @return \core_customfield\data_controller[]
*/
public function get_custom_fields(): array {
public function get_custom_fields() : array {
if (!isset($this->record->customfields)) {
$this->record->customfields = \core_course\customfield\course_handler::create()->get_instance_data($this->id);
}
@@ -217,7 +217,7 @@ class core_course_list_element implements IteratorAggregate {
*
* @return bool
*/
public function has_custom_fields(): bool {
public function has_custom_fields() : bool {
$customfields = $this->get_custom_fields();
return !empty($customfields);
}
+6 -3
View File
@@ -682,7 +682,8 @@ class core_course_external extends external_api {
new external_single_structure(
['name' => new external_value(PARAM_TEXT, 'The name of the custom field'),
'shortname' => new external_value(PARAM_ALPHANUMEXT, 'The shortname of the custom field'),
'type' => new external_value(PARAM_COMPONENT, 'The type of the custom field - text, checkbox...'),
'type' => new external_value(PARAM_COMPONENT,
'The type of the custom field - text, checkbox...'),
'value' => new external_value(PARAM_RAW, 'The value of the custom field')]
), 'Custom fields and associated values', VALUE_OPTIONAL),
), 'course'
@@ -2548,8 +2549,10 @@ class core_course_external extends external_api {
new external_single_structure(
array(
'name' => new external_value(PARAM_RAW, 'The name of the custom field'),
'shortname' => new external_value(PARAM_RAW, 'The shortname of the custom field - to be able to build the field class in the code'),
'type' => new external_value(PARAM_ALPHANUMEXT, 'The type of the custom field - text field, checkbox...'),
'shortname' => new external_value(PARAM_RAW,
'The shortname of the custom field - to be able to build the field class in the code'),
'type' => new external_value(PARAM_ALPHANUMEXT,
'The type of the custom field - text field, checkbox...'),
'value' => new external_value(PARAM_RAW, 'The value of the custom field'),
)
), 'Custom fields', VALUE_OPTIONAL),
+1 -1
View File
@@ -409,7 +409,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
// Enable course themes.
set_config('allowcoursethemes', 1);
// Custom fields
// Custom fields.
$fieldcategory = self::getDataGenerator()->create_custom_field_category(['name' => 'Other fields']);
$customfield = ['shortname' => 'test', 'name' => 'Custom field', 'type' => 'text',
+6 -6
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'));
@@ -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');
+1 -1
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,
+3 -3
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]);
}
+1 -1
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,
+7 -7
View File
@@ -82,7 +82,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.
@@ -122,7 +122,7 @@ abstract class data_controller {
*
* @return string
*/
protected function get_form_element_name(): string {
protected function get_form_element_name() : string {
return 'customfield_' . $this->get_field()->get('shortname');
}
@@ -185,7 +185,7 @@ abstract class data_controller {
*
* @return field_controller
*/
public function get_field(): field_controller {
public function get_field() : field_controller {
return $this->field;
}
@@ -223,7 +223,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 === '';
}
@@ -236,7 +236,7 @@ abstract class data_controller {
* @param mixed $value
* @return bool
*/
protected function is_unique($value): bool {
protected function is_unique($value) : bool {
global $DB;
$datafield = $this->datafield();
$where = "fieldid = ? AND {$datafield} = ?";
@@ -255,7 +255,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) {
@@ -281,7 +281,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));
@@ -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(),
@@ -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(),
@@ -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(),
+1 -1
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(),
+1 -1
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(),
+1 -1
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(),
+2 -2
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();
}
}
+6 -6
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.
@@ -132,7 +132,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();
}
@@ -167,7 +167,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();
@@ -196,7 +196,7 @@ abstract class field_controller {
*
* @return category_controller
*/
public final function get_category(): category_controller {
public final function get_category() : category_controller {
return $this->category;
}
@@ -219,7 +219,7 @@ abstract class field_controller {
*
* @return handler
*/
public final function get_handler(): handler {
public final function get_handler() : handler {
return $this->get_category()->get_handler();
}
@@ -245,7 +245,7 @@ abstract class field_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]);
}
+15 -15
View File
@@ -174,7 +174,7 @@ abstract class handler {
*
* @return bool
*/
public function uses_categories(): bool {
public function uses_categories() : bool {
return true;
}
@@ -184,7 +184,7 @@ abstract class handler {
* @param field_controller $field
* @return field_config_form
*/
public function get_field_config_form(field_controller $field): field_config_form {
public function get_field_config_form(field_controller $field) : field_config_form {
$form = new field_config_form(null, ['field' => $field]);
$form->set_data(api::prepare_field_for_config_form($field));
return $form;
@@ -210,7 +210,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()];
@@ -236,7 +236,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');
@@ -251,7 +251,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');
}
@@ -293,7 +293,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();
@@ -317,7 +317,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();
@@ -342,7 +342,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
@@ -355,7 +355,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
@@ -369,7 +369,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
@@ -460,7 +460,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 = '';
@@ -729,7 +729,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) {
@@ -746,7 +746,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) {
@@ -761,7 +761,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) {
@@ -798,7 +798,7 @@ abstract class handler {
* @param field_controller $field
* @return string page heading
*/
public function setup_edit_page(field_controller $field): string {
public function setup_edit_page(field_controller $field) : string {
global $PAGE;
// Page context.
+4 -4
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;
}
+1 -1
View File
@@ -325,7 +325,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
* @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!');
@@ -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']) {
@@ -76,7 +76,7 @@ class customfield_checkbox_plugin_testcase 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');
}
@@ -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();
@@ -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';
}
+1 -1
View File
@@ -73,7 +73,7 @@ class customfield_date_plugin_testcase 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');
}
@@ -96,7 +96,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.
@@ -61,7 +61,7 @@ class field_controller extends \core_customfield\field_controller {
* @param \core_customfield\field_controller $field
* @return array
*/
public static function get_options_array(\core_customfield\field_controller $field): array {
public static function get_options_array(\core_customfield\field_controller $field) : array {
if ($field->get_configdata_property('options')) {
$options = preg_split("/\s*\n\s*/", trim($field->get_configdata_property('options')));
} else {
@@ -78,7 +78,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) {
@@ -77,7 +77,7 @@ class customfield_select_plugin_testcase 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');
}
@@ -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');
@@ -91,7 +91,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);
+1 -1
View File
@@ -82,7 +82,7 @@ class customfield_text_plugin_testcase 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');
}
@@ -59,7 +59,7 @@ class data_controller extends \core_customfield\data_controller {
*
* @return string
*/
protected function get_form_element_name(): string {
protected function get_form_element_name() : string {
return parent::get_form_element_name() . '_editor';
}
@@ -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();
@@ -78,7 +78,7 @@ class customfield_textarea_plugin_testcase 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');
}
+2 -2
View File
@@ -39,7 +39,7 @@
"itemid": 0,
"usescategories": 1,
"categories": [
{ "id": 0,
{ "id": "0",
"nameeditable": "Other fields",
"addfieldmenu": "Add field",
"fields": [
@@ -47,7 +47,7 @@
{ "id": 0, "name": "Another field", "shortname": "checkme", "type": "Checkbox" }
]
},
{ "id": 0,
{ "id": "00",
"nameeditable": "Empty category",
"addfieldmenu": "Add field",
"fields": [] }
+1 -1
View File
@@ -48,7 +48,7 @@ class core_customfield_api_testcase 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');
}
@@ -47,7 +47,7 @@ class core_customfield_category_controller_testcase 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');
}
+1 -1
View File
@@ -45,7 +45,7 @@ class core_customfield_data_controller_testcase 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');
}
+1 -1
View File
@@ -49,7 +49,7 @@ class core_customfield_field_controller_testcase 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');
}
+2 -2
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;
@@ -149,7 +149,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);
+1 -1
View File
@@ -39,7 +39,7 @@ class core_customfield_generator_testcase 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');
}
+1 -1
View File
@@ -93,7 +93,7 @@ class core_customfield_privacy_testcase extends provider_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');
}
+4
View File
@@ -7262,6 +7262,10 @@ class admin_setting_manageformats extends admin_setting {
/**
* Custom fields manager. Allows to enable/disable custom fields and jump to settings.
*
* @package core
* @copyright 2018 Toni Barbera
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_setting_managecustomfields extends admin_setting {
+4 -1
View File
@@ -30,6 +30,10 @@ defined('MOODLE_INTERNAL') || die();
/**
* Class for admin tool plugins
*
* @package core
* @copyright 2018 Toni Barbera {@link http://www.moodle.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class customfield extends base {
@@ -80,7 +84,6 @@ class customfield extends base {
* This is intended for disabling of plugin, some DB table purging, etc.
*
* NOTE: to be called from uninstall_plugin() only.
* @private
*/
public function uninstall_cleanup() {
global $DB;
+3 -3
View File
@@ -427,7 +427,7 @@ EOD;
}
if (!empty($record['customfields'])) {
foreach($record['customfields'] as $field) {
foreach ($record['customfields'] as $field) {
$record['customfield_'.$field['shortname']] = $field['value'];
}
}
@@ -1185,7 +1185,7 @@ EOD;
* @param array $data Array with data['name'] of category
* @return \core_customfield\category_controller The created category
*/
public function create_custom_field_category($data): \core_customfield\category_controller {
public function create_custom_field_category($data) : \core_customfield\category_controller {
return $this->get_plugin_generator('core_customfield')->create_category($data);
}
@@ -1195,7 +1195,7 @@ EOD;
* @param array $data Array with 'name', 'shortname' and 'type' of the field
* @return \core_customfield\field_controller The created field
*/
public function create_custom_field($data): \core_customfield\field_controller {
public function create_custom_field($data) : \core_customfield\field_controller {
global $DB;
if (empty($data['categoryid']) && !empty($data['category'])) {
$data['categoryid'] = $DB->get_field('customfield_category', 'id', ['name' => $data['category']]);