From 5c6ee6ec362e31822b52fecfcaa98d0be84d318f Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 24 Mar 2011 13:30:46 +0100 Subject: [PATCH 1/2] MDL-26964 URL returned by moodle_url::out_omit_querystring() may contain the anchor part --- lib/weblib.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/weblib.php b/lib/weblib.php index 6141c1124d793..cb65a20d9deaf 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -541,14 +541,21 @@ public function out($escaped = true, array $overrideparams = null) { /** * Returns url without parameters, everything before '?'. + * + * @param bool $includeanchor if {@link self::anchor} is defined, should it be returned? * @return string */ - public function out_omit_querystring() { + public function out_omit_querystring($includeanchor = false) { + $uri = $this->scheme ? $this->scheme.':'.((strtolower($this->scheme) == 'mailto') ? '':'//'): ''; $uri .= $this->user ? $this->user.($this->pass? ':'.$this->pass:'').'@':''; $uri .= $this->host ? $this->host : ''; $uri .= $this->port ? ':'.$this->port : ''; $uri .= $this->path ? $this->path : ''; + if ($includeanchor and !is_null($this->anchor)) { + $uri .= '#' . $this->anchor; + } + return $uri; } From a12cd69c9e0f79e7e5369b2ecffe00844b508a4f Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 24 Mar 2011 14:25:40 +0100 Subject: [PATCH 2/2] MDL-26964 URL anchor support for single_button and single_select If the single_button or single_select use HTTP method 'get' then the eventual anchor part of the URL is used. --- lib/outputrenderers.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index d7516e1b93664..6d89aba67e6e0 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1124,7 +1124,11 @@ protected function render_single_button(single_button $button) { $output = html_writer::tag('div', $output); // now the form itself around it - $url = $button->url->out_omit_querystring(); // url without params + if ($button->method === 'get') { + $url = $button->url->out_omit_querystring(true); // url without params, the anchor part allowed + } else { + $url = $button->url->out_omit_querystring(); // url without params, the anchor part not allowed + } if ($url === '') { $url = '#'; // there has to be always some action } @@ -1210,8 +1214,13 @@ protected function render_single_select(single_select $select) { $output = html_writer::tag('div', $output); // now the form itself around it + if ($select->method === 'get') { + $url = $select->url->out_omit_querystring(true); // url without params, the anchor part allowed + } else { + $url = $select->url->out_omit_querystring(); // url without params, the anchor part not allowed + } $formattributes = array('method' => $select->method, - 'action' => $select->url->out_omit_querystring(), + 'action' => $url, 'id' => $select->formid); $output = html_writer::tag('form', $output, $formattributes);