original_string: public static function submit_tags_form($questionid, $contextid, $formdata) {
          global $DB, $CFG;
  
          $data = [];
          $result = ['status' => false];
  
          // Parameter validation.
          $params = self::validate_parameters(self::submit_tags_form_parameters(), [
              'questionid' => $questionid,
              'contextid' => $contextid,
              'formdata' => $formdata
          ]);
  
          $editingcontext = \context::instance_by_id($contextid);
          self::validate_context($editingcontext);
          parse_str($params['formdata'], $data);
  
          if (!$question = $DB->get_record_sql('
                  SELECT q.*, qc.contextid
                  FROM {question} q
                  JOIN {question_categories} qc ON qc.id = q.category
                  WHERE q.id = ?', [$questionid])) {
              print_error('questiondoesnotexist', 'question');
          }
  
          require_once($CFG->libdir . '/questionlib.php');
          require_once($CFG->dirroot . '/question/type/tags_form.php');
  
          $cantag = question_has_capability_on($question, 'tag');
          $questioncontext = \context::instance_by_id($question->contextid);
          $contexts = new \question_edit_contexts($editingcontext);
  
          $formoptions = [
              'editingcontext' => $editingcontext,
              'questioncontext' => $questioncontext,
              'contexts' => $contexts->all()
          ];
  
          $mform = new \core_question\form\tags(null, $formoptions, 'post', '', null, $cantag, $data);
  
          if ($validateddata = $mform->get_data()) {
              if ($cantag) {
                  if (isset($validateddata->tags)) {
                      // Due to a mform bug, if there's no tags set on the tag element, it submits the name as the value.
                      // The only way to discover is checking if the tag element is an array.
                      $tags = is_array($validateddata->tags) ? $validateddata->tags : [];
  
                      core_tag_tag::set_item_tags('core_question', 'question', $validateddata->id,
                          $questioncontext, $tags);
  
                      $result['status'] = true;
                  }
  
                  if (isset($validateddata->coursetags)) {
                      $coursetags = is_array($validateddata->coursetags) ? $validateddata->coursetags : [];
                      core_tag_tag::set_item_tags('core_question', 'question', $validateddata->id,
                          $editingcontext->get_course_context(false), $coursetags);
  
                      $result['status'] = true;
                  }
              }
          }
  
          return $result;
      }
code: public static function submit_tags_form($questionid, $contextid, $formdata) {
          global $DB, $CFG;
  
          $data = [];
          $result = ['status' => false];
  
          // Parameter validation.
          $params = self::validate_parameters(self::submit_tags_form_parameters(), [
              'questionid' => $questionid,
              'contextid' => $contextid,
              'formdata' => $formdata
          ]);
  
          $editingcontext = \context::instance_by_id($contextid);
          self::validate_context($editingcontext);
          parse_str($params['formdata'], $data);
  
          if (!$question = $DB->get_record_sql('
                  SELECT q.*, qc.contextid
                  FROM {question} q
                  JOIN {question_categories} qc ON qc.id = q.category
                  WHERE q.id = ?', [$questionid])) {
              print_error('questiondoesnotexist', 'question');
          }
  
          require_once($CFG->libdir . '/questionlib.php');
          require_once($CFG->dirroot . '/question/type/tags_form.php');
  
          $cantag = question_has_capability_on($question, 'tag');
          $questioncontext = \context::instance_by_id($question->contextid);
          $contexts = new \question_edit_contexts($editingcontext);
  
          $formoptions = [
              'editingcontext' => $editingcontext,
              'questioncontext' => $questioncontext,
              'contexts' => $contexts->all()
          ];
  
          $mform = new \core_question\form\tags(null, $formoptions, 'post', '', null, $cantag, $data);
  
          if ($validateddata = $mform->get_data()) {
              if ($cantag) {
                  if (isset($validateddata->tags)) {
                      // Due to a mform bug, if there's no tags set on the tag element, it submits the name as the value.
                      // The only way to discover is checking if the tag element is an array.
                      $tags = is_array($validateddata->tags) ? $validateddata->tags : [];
  
                      core_tag_tag::set_item_tags('core_question', 'question', $validateddata->id,
                          $questioncontext, $tags);
  
                      $result['status'] = true;
                  }
  
                  if (isset($validateddata->coursetags)) {
                      $coursetags = is_array($validateddata->coursetags) ? $validateddata->coursetags : [];
                      core_tag_tag::set_item_tags('core_question', 'question', $validateddata->id,
                          $editingcontext->get_course_context(false), $coursetags);
  
                      $result['status'] = true;
                  }
              }
          }
  
          return $result;
      }
code_tokens: public static function submit_tags_form ( $ questionid , $ contextid , $ formdata ) { global $ DB , $ CFG ; $ data = [ ] ; $ result = [ 'status' => false ] ; // Parameter validation. $ params = self :: validate_parameters ( self :: submit_tags_form_parameters ( ) , [ 'questionid' => $ questionid , 'contextid' => $ contextid , 'formdata' => $ formdata ] ) ; $ editingcontext = \ context :: instance_by_id ( $ contextid ) ; self :: validate_context ( $ editingcontext ) ; parse_str ( $ params [ 'formdata' ] , $ data ) ; if ( ! $ question = $ DB -> get_record_sql ( '
                  SELECT q.*, qc.contextid
                  FROM {question} q
                  JOIN {question_categories} qc ON qc.id = q.category
                  WHERE q.id = ?' , [ $ questionid ] ) ) { print_error ( 'questiondoesnotexist' , 'question' ) ; } require_once ( $ CFG -> libdir . '/questionlib.php' ) ; require_once ( $ CFG -> dirroot . '/question/type/tags_form.php' ) ; $ cantag = question_has_capability_on ( $ question , 'tag' ) ; $ questioncontext = \ context :: instance_by_id ( $ question -> contextid ) ; $ contexts = new \ question_edit_contexts ( $ editingcontext ) ; $ formoptions = [ 'editingcontext' => $ editingcontext , 'questioncontext' => $ questioncontext , 'contexts' => $ contexts -> all ( ) ] ; $ mform = new \ core_question \ form \ tags ( null , $ formoptions , 'post' , '' , null , $ cantag , $ data ) ; if ( $ validateddata = $ mform -> get_data ( ) ) { if ( $ cantag ) { if ( isset ( $ validateddata -> tags ) ) { // Due to a mform bug, if there's no tags set on the tag element, it submits the name as the value. // The only way to discover is checking if the tag element is an array. $ tags = is_array ( $ validateddata -> tags ) ? $ validateddata -> tags : [ ] ; core_tag_tag :: set_item_tags ( 'core_question' , 'question' , $ validateddata -> id , $ questioncontext , $ tags ) ; $ result [ 'status' ] = true ; } if ( isset ( $ validateddata -> coursetags ) ) { $ coursetags = is_array ( $ validateddata -> coursetags ) ? $ validateddata -> coursetags : [ ] ; core_tag_tag :: set_item_tags ( 'core_question' , 'question' , $ validateddata -> id , $ editingcontext -> get_course_context ( false ) , $ coursetags ) ; $ result [ 'status' ] = true ; } } } return $ result ; }
docstring: Handles the tags form submission.
  
  @param int $questionid The question id.
  @param int $contextid The editing context id.
  @param string $formdata The question tag form data in a URI encoded param string
  @return array The created or modified question tag
docstring_tokens: Handles the tags form submission .