Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'MDL-26964-moodle_url-anchor_master' of git://github.com…
…/mudrd8mz/moodle
  • Loading branch information
skodak committed Mar 29, 2011
2 parents 4b59f32 + a12cd69 commit 3b6d215
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/outputrenderers.php
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);

Expand Down
9 changes: 8 additions & 1 deletion lib/weblib.php
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3b6d215

Please sign in to comment.