/user/profile/field/menu/define.class.php
PHP | 41 lines | 25 code | 12 blank | 4 comment | 1 complexity | f5de623f605e45e9eb8f4c81094c3cf0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
- <?php
- class profile_define_menu extends profile_define_base {
- function define_form_specific($form) {
- /// Param 1 for menu type contains the options
- $form->addElement('textarea', 'param1', get_string('profilemenuoptions', 'admin'), array('rows' => 6, 'cols' => 40));
- $form->setType('param1', PARAM_TEXT);
- /// Default data
- $form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"');
- $form->setType('defaultdata', PARAM_TEXT);
- }
- function define_validate_specific($data, $files) {
- $err = array();
- $data->param1 = str_replace("\r", '', $data->param1);
- /// Check that we have at least 2 options
- if (($options = explode("\n", $data->param1)) === false) {
- $err['param1'] = get_string('profilemenunooptions', 'admin');
- } elseif (count($options) < 2) {
- $err['param1'] = get_string('profilemenutoofewoptions', 'admin');
- /// Check the default data exists in the options
- } elseif (!empty($data->defaultdata) and !in_array($data->defaultdata, $options)) {
- $err['defaultdata'] = get_string('profilemenudefaultnotinoptions', 'admin');
- }
- return $err;
- }
- function define_save_preprocess($data) {
- $data->param1 = str_replace("\r", '', $data->param1);
- return $data;
- }
- }