MDL-57898 core_customfield: Custom fields API

This commit is part of work on Custom fields API,
to minimize commit history in moodle core the work of a team of developers was split
into several commits with different authors but the authorship of individual
lines of code may be different from the commit author.
This commit is contained in:
Daniel Neis Araujo
2019-01-18 14:28:17 +01:00
committed by Marina Glancy
parent 0446fee7a9
commit 01c1095954
35 changed files with 2761 additions and 0 deletions
+119
View File
@@ -7260,6 +7260,125 @@ class admin_setting_manageformats extends admin_setting {
}
}
/**
* Custom fields manager. Allows to enable/disable custom fields and jump to settings.
*/
class admin_setting_managecustomfields extends admin_setting {
/**
* Calls parent::__construct with specific arguments
*/
public function __construct() {
$this->nosave = true;
parent::__construct('customfieldsui', new lang_string('managecustomfields', 'core_admin'), '', '');
}
/**
* Always returns true
*
* @return true
*/
public function get_setting() {
return true;
}
/**
* Always returns true
*
* @return true
*/
public function get_defaultsetting() {
return true;
}
/**
* Always returns '' and doesn't write anything
*
* @param mixed $data string or array, must not be NULL
* @return string Always returns ''
*/
public function write_setting($data) {
// Do not write any setting.
return '';
}
/**
* Search to find if Query is related to format plugin
*
* @param string $query The string to search for
* @return bool true for related false for not
*/
public function is_related($query) {
if (parent::is_related($query)) {
return true;
}
$formats = core_plugin_manager::instance()->get_plugins_of_type('customfield');
foreach ($formats as $format) {
if (strpos($format->component, $query) !== false ||
strpos(core_text::strtolower($format->displayname), $query) !== false) {
return true;
}
}
return false;
}
/**
* Return XHTML to display control
*
* @param mixed $data Unused
* @param string $query
* @return string highlight
*/
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
$return = '';
$return = $OUTPUT->heading(new lang_string('customfields'), 3, 'main');
$return .= $OUTPUT->box_start('generalbox customfieldsui');
$fields = core_plugin_manager::instance()->get_plugins_of_type('customfield');
$txt = get_strings(array('settings', 'name', 'enable', 'disable', 'up', 'down'));
$txt->uninstall = get_string('uninstallplugin', 'core_admin');
$txt->updown = "$txt->up/$txt->down";
$table = new html_table();
$table->head = array($txt->name, $txt->enable, $txt->uninstall, $txt->settings);
$table->align = array('left', 'center', 'center', 'center');
$table->attributes['class'] = 'managecustomfieldtable generaltable admintable';
$table->data = array();
$spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'iconsmall'));
foreach ($fields as $field) {
$url = new moodle_url('/admin/customfields.php',
array('sesskey' => sesskey(), 'field' => $field->name));
if ($field->is_enabled()) {
$strfieldname = $field->displayname;
$hideshow = html_writer::link($url->out(false, array('action' => 'disable')),
$OUTPUT->pix_icon('t/hide', $txt->disable, 'moodle', array('class' => 'iconsmall')));
} else {
$strfieldname = $field->displayname;
$class = 'dimmed_text';
$hideshow = html_writer::link($url->out(false, array('action' => 'enable')),
$OUTPUT->pix_icon('t/show', $txt->enable, 'moodle', array('class' => 'iconsmall')));
}
$settings = '';
if ($field->get_settings_url()) {
$settings = html_writer::link($field->get_settings_url(), $txt->settings);
}
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('customfield_'.$field->name, 'manage')) {
$uninstall = html_writer::link($uninstallurl, $txt->uninstall);
}
$row = new html_table_row(array($strfieldname, $hideshow, $uninstall, $settings));
$table->data[] = $row;
}
$return .= html_writer::table($table);
$return .= $OUTPUT->box_end();
return highlight($query, $return);
}
}
/**
* Data formats manager. Allow reorder and to enable/disable data formats and jump to settings
*