title: Moodle: Using the returnto query parameter to redirect back to my local plugins index after course edit
body: <p>tl;dr; Trying to link the 'save and return' button when editing/deleting a course to my local plugins index.php instead of moodles default redirect for these features, moodle allready has a <code>returnTo</code> query parameter so i was thinking if that could be used somehow. </p>
  
  <p>Hey</p>
  
  <p>I am creating a local plugin that has a administration panel, where you can access CRUD on all courses in the system as seen in the picture below:
  <a href="https://i.stack.imgur.com/7cghP.png" rel="nofollow"><img src="https://i.stack.imgur.com/7cghP.png" alt="enter image description here"></a></p>
  
  <p>The problem now is that whenever I click edit, I get into the course edit page of course, but when I return from there I click "save and return" I would like to get back to my own admin page instead of the course page or category manage page.   </p>
  
  <p>The code I have right now looks like this:</p>
  
  <pre><code>//edit
  $edit_course_moodle_url = new moodle_url('/course/edit.php', array('id' =&gt; $course-&gt;id, 'returnto' =&gt; 'local/adminpanel/index.php'));
  $edit_course_url = $edit_course_moodle_url-&gt;get_path() . '?id=' . $edit_course_moodle_url-&gt;get_param('id') . '&amp;returnto=' . $edit_course_moodle_url-&gt;get_param('returnto');
  
  //delete
  $delete_course_moodle_url = new moodle_url('/course/delete.php', array('id' =&gt; $course-&gt;id, 'returnto' =&gt; 'local/adminpanel/index.php'));
  $delete_course_url = $delete_course_moodle_url-&gt;get_path() . '?id=' . $delete_course_moodle_url-&gt;get_param('id') . '&amp;returnto=' . $delete_course_moodle_url-&gt;get_param('returnto');
  </code></pre>
  
  <p>As you can see I use the "returnto" query parameter, normally moodle has a "<code>catmanage</code>" as "<code>returnto</code>" that returns you to the category management page, where moodle has its own CRUD for categories and courses. So my question is, can I create my own alias for a link and use it like moodle uses the <code>catmanage</code> link, but for my admin page instead.</p>
  
  <p>Thanks a lot ! :)</p>
  
  <p>EDIT:</p>
  
  <p>Change code to the following:</p>
  
  <pre><code>if (empty($CFG-&gt;loginhttps)) {
      $securewwwroot = $CFG-&gt;wwwroot;
  } else {
      $securewwwroot = str_replace('http:','https:',$CFG-&gt;wwwroot);
  }
  $returnurl = new moodle_url($securewwwroot . '/local/adminpanel/index.php');
  
  $edit_course_moodle_url = new moodle_url($securewwwroot . '/course/edit.php', array(
              'id' =&gt; $course-&gt;id,
              'sesskey' =&gt; sesskey(),
              'returnto' =&gt; 'url',
              'returnurl' =&gt; $returnurl-&gt;out(false))
          );
  
          $edit_course_url =  $edit_course_moodle_url-&gt;out();
  </code></pre>
  
  <p>But it looks like moodle took away the button from edit course called "save and return" now it only has  "save and display" or "Cancel" , both of which brings me back to the course,  sad times :(</p>