MDL-61837 core_question: replace tag fields on tag modal
authorSimey Lameze <simey@moodle.com>
Wed, 4 Apr 2018 01:49:42 +0000 (09:49 +0800)
committerSimey Lameze <simey@moodle.com>
Mon, 9 Apr 2018 03:46:46 +0000 (11:46 +0800)
question/classes/external.php
question/lib.php
question/type/tags_form.php

index f2011d4..ce21a30 100644 (file)
@@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die();
 
 require_once("$CFG->libdir/externallib.php");
 require_once($CFG->dirroot . '/question/engine/lib.php');
+require_once($CFG->libdir . '/questionlib.php');
 
 /**
  * Question external functions
@@ -166,9 +167,12 @@ class core_question_external extends external_api {
 
         $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
+            'questioncontext' => $questioncontext,
+            'contexts' => $contexts->all()
         ];
 
         $mform = new \core_question\form\tags(null, $formoptions, 'post', '', null, $cantag, $data);
index 5a731c4..209d06b 100644 (file)
@@ -58,10 +58,12 @@ function core_question_output_fragment_tags_form($args) {
 
         $category = $question->categoryobject;
         $questioncontext = \context::instance_by_id($category->contextid);
+        $contexts = new \question_edit_contexts($editingcontext);
 
         $formoptions = [
             'editingcontext' => $editingcontext,
-            'questioncontext' => $questioncontext
+            'questioncontext' => $questioncontext,
+            'contexts' => $contexts->all()
         ];
         $data = [
             'id' => $question->id,
index bcc2fc5..cca587f 100644 (file)
@@ -27,7 +27,7 @@ namespace core_question\form;
 defined('MOODLE_INTERNAL') || die();
 
 require_once($CFG->dirroot . '/lib/formslib.php');
-
+require_once($CFG->dirroot . '/lib/questionlib.php');
 /**
  * The mform class for  manage question tags.
  *
@@ -59,8 +59,18 @@ class tags extends \moodleform {
         $mform->addElement('static', 'context', '');
 
         if (\core_tag_tag::is_enabled('core_question', 'question')) {
-            $mform->addElement('tags', 'tags', get_string('tags'),
-                    ['itemtype' => 'question', 'component' => 'core_question']);
+            $tags = \core_tag_tag::get_tags_by_area_in_contexts('core_question', 'question', $customdata['contexts']);
+            $tagstrings = [];
+            foreach ($tags as $tag) {
+                $tagstrings[$tag->name] = $tag->name;
+            }
+
+            $options = [
+                'tags' => true,
+                'multiple' => true,
+                'noselectionstring' => get_string('anytags', 'quiz'),
+            ];
+            $mform->addElement('autocomplete', 'tags',  get_string('tags'), $tagstrings, $options);
 
             // Is the question category in a course context?
             $qcontext = $customdata['questioncontext'];
@@ -77,8 +87,7 @@ class tags extends \moodleform {
                 // allow course tags to be added to the course.
                 $coursetagheader = get_string('questionformtagheader', 'core_question',
                     $editingcoursecontext->get_context_name(true));
-                $mform->addElement('tags', 'coursetags', $coursetagheader,
-                        array('itemtype' => 'question', 'component' => 'core_question'));
+                $mform->addElement('autocomplete', 'coursetags',  $coursetagheader, $tagstrings, $options);
 
             }
         }