original_string: public function instance_form_definition(\MoodleQuickForm $mform, int $instanceid = 0) {
  
          $editablefields = $this->get_editable_fields($instanceid);
          $fieldswithdata = api::get_instance_fields_data($editablefields, $instanceid);
          $lastcategoryid = null;
          foreach ($fieldswithdata as $data) {
              $categoryid = $data->get_field()->get_category()->get('id');
              if ($categoryid != $lastcategoryid) {
                  $mform->addElement('header', 'category_' . $categoryid,
                      format_string($data->get_field()->get_category()->get('name')));
                  $lastcategoryid = $categoryid;
              }
              $data->instance_form_definition($mform);
              $field = $data->get_field()->to_record();
              if (strlen($field->description)) {
                  // Add field description.
                  $context = $this->get_configuration_context();
                  $value = file_rewrite_pluginfile_urls($field->description, 'pluginfile.php',
                      $context->id, 'core_customfield', 'description', $field->id);
                  $value = format_text($value, $field->descriptionformat, ['context' => $context]);
                  $mform->addElement('static', 'customfield_' . $field->shortname . '_static', '', $value);
              }
          }
      }
code: public function instance_form_definition(\MoodleQuickForm $mform, int $instanceid = 0) {
  
          $editablefields = $this->get_editable_fields($instanceid);
          $fieldswithdata = api::get_instance_fields_data($editablefields, $instanceid);
          $lastcategoryid = null;
          foreach ($fieldswithdata as $data) {
              $categoryid = $data->get_field()->get_category()->get('id');
              if ($categoryid != $lastcategoryid) {
                  $mform->addElement('header', 'category_' . $categoryid,
                      format_string($data->get_field()->get_category()->get('name')));
                  $lastcategoryid = $categoryid;
              }
              $data->instance_form_definition($mform);
              $field = $data->get_field()->to_record();
              if (strlen($field->description)) {
                  // Add field description.
                  $context = $this->get_configuration_context();
                  $value = file_rewrite_pluginfile_urls($field->description, 'pluginfile.php',
                      $context->id, 'core_customfield', 'description', $field->id);
                  $value = format_text($value, $field->descriptionformat, ['context' => $context]);
                  $mform->addElement('static', 'customfield_' . $field->shortname . '_static', '', $value);
              }
          }
      }
code_tokens: public function instance_form_definition ( \ MoodleQuickForm $ mform , int $ instanceid = 0 ) { $ editablefields = $ this -> get_editable_fields ( $ instanceid ) ; $ fieldswithdata = api :: get_instance_fields_data ( $ editablefields , $ instanceid ) ; $ lastcategoryid = null ; foreach ( $ fieldswithdata as $ data ) { $ categoryid = $ data -> get_field ( ) -> get_category ( ) -> get ( 'id' ) ; if ( $ categoryid != $ lastcategoryid ) { $ mform -> addElement ( 'header' , 'category_' . $ categoryid , format_string ( $ data -> get_field ( ) -> get_category ( ) -> get ( 'name' ) ) ) ; $ lastcategoryid = $ categoryid ; } $ data -> instance_form_definition ( $ mform ) ; $ field = $ data -> get_field ( ) -> to_record ( ) ; if ( strlen ( $ field -> description ) ) { // Add field description. $ context = $ this -> get_configuration_context ( ) ; $ value = file_rewrite_pluginfile_urls ( $ field -> description , 'pluginfile.php' , $ context -> id , 'core_customfield' , 'description' , $ field -> id ) ; $ value = format_text ( $ value , $ field -> descriptionformat , [ 'context' => $ context ] ) ; $ mform -> addElement ( 'static' , 'customfield_' . $ field -> shortname . '_static' , '' , $ value ) ; } } }
docstring: Adds custom fields to instance editing form
  
  Example:
  public function definition() {
  // ... normal instance definition, including hidden 'id' field.
  $handler->instance_form_definition($this->_form, $instanceid);
  $this->add_action_buttons();
  }
  
  @param \MoodleQuickForm $mform
  @param int $instanceid id of the instance, can be null when instance is being created
docstring_tokens: Adds custom fields to instance editing form