/** * Add the disabledIf values. * * @param MoodleQuickForm $mform The form to add configuration to. */ public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { $myvalue = \tool_usertours\target::get_target_constant_for_class(get_class()); foreach (array_keys(self::$forcedsettings) as $settingname) { $mform->disabledIf($settingname, 'targettype', 'eq', $myvalue); } }
/** * Form definition. */ public function definition() { $mform = $this->_form; $mform->addElement('header', 'heading_target', get_string('target_heading', 'tool_usertours')); $types = []; foreach (\tool_usertours\target::get_target_types() as $value => $type) { $types[$value] = get_string('target_' . $type, 'tool_usertours'); } $mform->addElement('select', 'targettype', get_string('targettype', 'tool_usertours'), $types); $mform->addHelpButton('targettype', 'targettype', 'tool_usertours'); // The target configuration. foreach (\tool_usertours\target::get_target_types() as $value => $type) { $targetclass = \tool_usertours\target::get_classname($type); $targetclass::add_config_to_form($mform); } // Content of the step. $mform->addElement('header', 'heading_content', get_string('content_heading', 'tool_usertours')); $mform->addElement('textarea', 'title', get_string('title', 'tool_usertours')); $mform->addRule('title', get_string('required'), 'required', null, 'client'); $mform->setType('title', PARAM_TEXT); $mform->addHelpButton('title', 'title', 'tool_usertours'); $mform->addElement('textarea', 'content', get_string('content', 'tool_usertours')); $mform->addRule('content', get_string('required'), 'required', null, 'client'); $mform->setType('content', PARAM_RAW); $mform->addHelpButton('content', 'content', 'tool_usertours'); // Add the step configuration. $mform->addElement('header', 'heading_options', get_string('options_heading', 'tool_usertours')); // All step configuration is defined in the step. $this->step->add_config_to_form($mform); // And apply any form constraints. foreach (\tool_usertours\target::get_target_types() as $value => $type) { $targetclass = \tool_usertours\target::get_classname($type); $targetclass::add_disabled_constraints_to_form($mform); } $this->add_action_buttons(); }
/** * Add the disabledIf values. * * @param MoodleQuickForm $mform The form to add configuration to. */ public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { $mform->disabledIf('targetvalue_selector', 'targettype', 'noteq', \tool_usertours\target::get_target_constant_for_class(get_class())); }