Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-60872

Callbacks for course edit form

XMLWordPrintable

    • MOODLE_35_STABLE
    • Hide

      The following test steps ensure that all four new callbacks have been called:

      1. Create or extend a plugin with these functions in lib.php:

        function [plugin]_course_edit_definition(course_edit_form $formwrapper, MoodleQuickForm $mform) {
            echo 'called course_edit_definition';
            $mform->addElement('header', 'testheader', 'new header');
            $mform->addElement('text', 'testfield', 'text field 1 (number > 100)');
            $mform->setType('testfield', PARAM_INT);
            $mform->addElement('text', 'testfield2', 'text field 2');
            $mform->setType('testfield2', PARAM_ALPHA);
        }
         
        function [plugin]_course_edit_definition_after_data(course_edit_form $formwrapper, MoodleQuickForm $mform) {
            echo 'called course_edit_definition_after_data';
            $mform->hardFreeze('testfield2');
            $mform->setConstant('testfield2', 'test');
        }
         
        function [plugin]_course_edit_validation(course_edit_form $formwrapper, array $data, array $files) {
            echo 'called course_edit_validation';
            $errors = [];
            if ($data['testfield'] <= 100) {
                $errors['testfield'] = 'Number must be greater than 100.';
            }
            return $errors;
        }
         
        function [plugin]_course_edit_post_actions(course_edit_form $formwrapper, $course) {
            echo 'called course_edit_post_actions';
            $data = $formwrapper->get_data();
            print_r($data);
        }
        

      2. Purge caches.
      3. Go to a course settings page and ensure there is a new heading called "new header" with two settings.
      4. "text field 2" should be frozen to 'test'.
      5. Try to save the form with the number 5 in "text field 1".
      6. A validation error should be shown.
      7. Set "text field 1" to 120 and save.
      8. The form data should be accepted and "called course_edit_post_actions" should be printed.
      Show
      The following test steps ensure that all four new callbacks have been called: Create or extend a plugin with these functions in lib.php: function [plugin]_course_edit_definition(course_edit_form $formwrapper , MoodleQuickForm $mform ) { echo 'called course_edit_definition' ; $mform ->addElement( 'header' , 'testheader' , 'new header' ); $mform ->addElement( 'text' , 'testfield' , 'text field 1 (number > 100)' ); $mform ->setType( 'testfield' , PARAM_INT); $mform ->addElement( 'text' , 'testfield2' , 'text field 2' ); $mform ->setType( 'testfield2' , PARAM_ALPHA); }   function [plugin]_course_edit_definition_after_data(course_edit_form $formwrapper , MoodleQuickForm $mform ) { echo 'called course_edit_definition_after_data' ; $mform ->hardFreeze( 'testfield2' ); $mform ->setConstant( 'testfield2' , 'test' ); }   function [plugin]_course_edit_validation(course_edit_form $formwrapper , array $data , array $files ) { echo 'called course_edit_validation' ; $errors = []; if ( $data [ 'testfield' ] <= 100) { $errors [ 'testfield' ] = 'Number must be greater than 100.' ; } return $errors ; }   function [plugin]_course_edit_post_actions(course_edit_form $formwrapper , $course ) { echo 'called course_edit_post_actions' ; $data = $formwrapper ->get_data(); print_r( $data ); } Purge caches. Go to a course settings page and ensure there is a new heading called "new header" with two settings. "text field 2" should be frozen to 'test'. Try to save the form with the number 5 in "text field 1". A validation error should be shown. Set "text field 1" to 120 and save. The form data should be accepted and "called course_edit_post_actions" should be printed.

      Hi,

      for a local plugin I am currently developing I need the possibility to change the course edit form (course/edit.php). I attached a patch which adds the necessary callbacks for doing that. Here are test functions for using the callbacks:

       

      function local_plugin_course_edit_definition($formwrapper, $mform) {
      }
       
      function local_plugin_course_edit_definition_after_data($formwrapper, $mform) {
      }
       
      function local_plugin_course_edit_validation($formwrapper, $data) {
      }
       
      function local_plugin_course_edit_process_data($course, $mform) {
      }
      

      Best Regards

      Justus

            Votes:
            4 Vote for this issue
            Watchers:
            28 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.