. /** * Customfield date plugin * * @package customfield_date * @copyright 2018 David Matamoros * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace customfield_date; defined('MOODLE_INTERNAL') || die; /** * Class field * * @package customfield_date * @copyright 2018 David Matamoros * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class field_controller extends \core_customfield\field_controller { /** * Type of plugin data */ const TYPE = 'date'; /** * Validate the data from the config form. * * @param array $data * @param array $files * @return array associative array of error messages */ public function config_form_validation(array $data, $files = array()) : array { $errors = array(); // Make sure the start year is not greater than the end year. if (!empty($data['configdata']['mindate']) && !empty($data['configdata']['maxdate']) && $data['configdata']['mindate'] > $data['configdata']['maxdate']) { $errors['configdata[mindate]'] = get_string('mindateaftermax', 'customfield_date'); } return $errors; } /** * Add fields for editing a date field. * * @param \MoodleQuickForm $mform */ public function config_form_definition(\MoodleQuickForm $mform) { $config = $this->get('configdata'); // Add elements. $mform->addElement('header', 'header_specificsettings', get_string('specificsettings', 'customfield_date')); $mform->setExpanded('header_specificsettings', true); $mform->addElement('advcheckbox', 'configdata[includetime]', get_string('includetime', 'customfield_date')); $mform->addElement('date_time_selector', 'configdata[mindate]', get_string('mindate', 'customfield_date'), ['optional' => true]); $mform->addElement('date_time_selector', 'configdata[maxdate]', get_string('maxdate', 'customfield_date'), ['optional' => true]); $mform->hideIf('configdata[maxdate][hour]', 'configdata[includetime]'); $mform->hideIf('configdata[maxdate][minute]', 'configdata[includetime]'); $mform->hideIf('configdata[mindate][hour]', 'configdata[includetime]'); $mform->hideIf('configdata[mindate][minute]', 'configdata[includetime]'); } }