title: file_postupdate_standard_editor function in Moodle
body: <p>code for editor in my <strong>moodle form</strong></p>
  
  <pre><code>$mform-&gt;addElement('editor', 'title_editor', 'Questions', null, array('maxfiles' =&gt; EDITOR_UNLIMITED_FILES));
  $mform-&gt;addRule('title', null, 'required', null, 'client');
  $mform-&gt;setType('title', PARAM_RAW);
  </code></pre>
  
  <p>(form contain other fields too)</p>
  
  <p>I submit the form and in action page I get the data as:</p>
  
  <pre><code>$data = $questionpool_form-&gt;get_data(true);
  </code></pre>
  
  <p><strong>$data</strong> is:</p>
  
  <pre><code>object(stdClass)[127]
    public 'title' =&gt; 
      array (size=3)
        'text' =&gt; string '&lt;p&gt;What is the image shown below:&lt;/p&gt;
  &lt;p&gt;&lt;img src="http://localhost/moodle/draftfile.php/5/user/draft/717102051/111.png" width="297" height="203" /&gt;&lt;/p&gt;' (length=153)
        'format' =&gt; string '1' (length=1)
        'itemid' =&gt; int 717102051
    public 'answer' =&gt; 
      array (size=2)
        'text' =&gt; string '&lt;p&gt;Brown color&lt;/p&gt;' (length=18)
        'format' =&gt; string '1' (length=1)
    public 'blockid' =&gt; string '' (length=0)
    public 'courseid' =&gt; string '' (length=0)
    public 'submitbutton' =&gt; string 'Proceed' (length=7)
  </code></pre>
  
  <p>Since the image is in draftfile students cannot see the image. So to save and relink embedded images I use:</p>
  
  <pre><code>$definitionoptions = array('maxfiles' =&gt; EDITOR_UNLIMITED_FILES);
  $data-&gt;id = null;
  $data = file_postupdate_standard_editor($data, 'title', $definitionoptions, $context, 'block_question', 'title', $data-&gt;id);
  </code></pre>
  
  <p>And I print(check) the new data variable</p>
  
  <pre><code>object(stdClass)[127]
    public 'title' =&gt; 
      array (size=3)
        'text' =&gt; string '&lt;p&gt;What is the image shown below:&lt;/p&gt;
  &lt;p&gt;&lt;img src="http://localhost/moodle/draftfile.php/5/user/draft/717102051/111.png" width="297" height="203" /&gt;&lt;/p&gt;' (length=153)
        'format' =&gt; string '1' (length=1)
        'itemid' =&gt; int 717102051
    public 'answer' =&gt; 
      array (size=2)
        'text' =&gt; string '&lt;p&gt;Brown color&lt;/p&gt;' (length=18)
        'format' =&gt; string '1' (length=1)
    public 'blockid' =&gt; string '' (length=0)
    public 'courseid' =&gt; string '' (length=0)
    public 'submitbutton' =&gt; string 'Proceed' (length=7)
    public 'id' =&gt; null
    public 'editortrust' =&gt; int 0
    public 'editor' =&gt; null
    public 'editorformat' =&gt; null
  </code></pre>
  
  <p>But the image location is the same and that will not visible to student.</p>
  
  <p><strong>My question is:</strong></p>
  
  <p>What is the mistake in my <code>file_postupdate_standard_editor</code> function?</p>
  
  <p>How can I save the image in correct location to display the images (if any) successfully?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>New <code>$data</code> variable after </p>
  
  <blockquote>
    <p>davosmith's</p>
  </blockquote>
  
  <p>answer</p>
  
  <pre><code>object(stdClass)[117]
    public 'title_editor' =&gt; 
      array (size=3)
        'text' =&gt; string '&lt;p&gt;Find the color??&lt;/p&gt;
  &lt;p&gt;&lt;img src="http://localhost/moodle/draftfile.php/5/user/draft/239105225/flower_123.jpeg" width="200" height="200" alt="fff" /&gt;&lt;/p&gt;' (length=157)
        'format' =&gt; string '1' (length=1)
        'itemid' =&gt; int 509796143
    public 'answer' =&gt; 
      array (size=2)
        'text' =&gt; string '&lt;p&gt;37&lt;/p&gt;' (length=9)
        'format' =&gt; string '1' (length=1)
    public 'blockid' =&gt; string '' (length=0)
    public 'courseid' =&gt; string '' (length=0)
    public 'submitbutton' =&gt; string 'Proceed' (length=7)
    public 'titletrust' =&gt; int 0
    public 'title' =&gt; string '&lt;p&gt;Find the color??&lt;/p&gt;
  &lt;p&gt;&lt;img src="http://localhost/moodle/draftfile.php/5/user/draft/239105225/flower_123.jpeg" width="200" height="200" alt="fff" /&gt;&lt;/p&gt;' (length=157)
    public 'titleformat' =&gt; string '1' (length=1)
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>My moodle form contain the function <strong>data_preprocessing</strong></p>
  
  <pre><code>function data_preprocessing(&amp;$data) {
          if ($this-&gt;current-&gt;instance) {
              $courseid = required_param('id', PARAM_INT); // Do not use $_GET directly.
              $course = $DB-&gt;get_record('course', ['id' =&gt; $courseid], '*', MUST_EXIST); // Optional, but you often need the course object.
              $context = context_course::instance($courseid);
              $contextid = $context-&gt;id;
              $textfieldoptions = array('maxfiles' =&gt; EDITOR_UNLIMITED_FILES);
              $draftitemid = file_get_submitted_draft_itemid('title_editor');
              $data['title_editor']['format'] = $data['contentformat'];
             // $data = file_prepare_standard_editor($data, 'title', $textfieldoptions, $context,'block_questionpool', 'title', 0);
              $data['title_editor']['text']   = file_prepare_draft_area($draftitemid, $contextid, 'block_questionpool', 'title', 0, page_get_editor_options($contextid), $data['title']);
              $data['title_editor']['itemid'] = $draftitemid;
  
          }
          if (!empty($data['displayoptions'])) {
              $displayoptions = unserialize($data['displayoptions']);
              if (isset($displayoptions['printintro'])) {
                  $data['printintro'] = $displayoptions['printintro'];
              }
              if (isset($displayoptions['printheading'])) {
                  $data['printheading'] = $displayoptions['printheading'];
              }
              if (!empty($displayoptions['popupwidth'])) {
                  $data['popupwidth'] = $displayoptions['popupwidth'];
              }
              if (!empty($displayoptions['popupheight'])) {
                  $data['popupheight'] = $displayoptions['popupheight'];
              }
          }
      }
  </code></pre>