diff --git a/wire/core/Page.php b/wire/core/Page.php index 0b4e383d..9b1f56ff 100644 --- a/wire/core/Page.php +++ b/wire/core/Page.php @@ -3145,10 +3145,12 @@ class Page extends WireData implements \Countable, WireMatchable { * ## $options argument * * You can specify an `$options` argument to this method with any of the following: - * - * - `pageNum` (int|string): Specify pagination number, or "+" for next pagination, or "-" for previous pagination. - * - `urlSegmentStr` (string): Specify a URL segment string to append. - * - `urlSegments` (array): Specify array of URL segments to append (may be used instead of urlSegmentStr). + * + * - `pageNum` (int|string|bool): Specify pagination number, "+" for next pagination, "-" for previous pagination, + * or boolean true (3.0.155+) for current. + * - `urlSegmentStr` (string|bool): Specify a URL segment string to append, or true (3.0.155+) for current. + * - `urlSegments` (array|bool): Specify array of URL segments to append (may be used instead of urlSegmentStr), + * or boolean true (3.0.155+) for current. Specify associative array to use keys and values in order (3.0.155+). * - `data` (array): Array of key=value variables to form a query string. * - `http` (bool): Specify true to make URL include scheme and hostname (default=false). * - `language` (Language): Specify Language object to return URL in that Language. diff --git a/wire/core/PageTraversal.php b/wire/core/PageTraversal.php index 3829c156..8c22f638 100644 --- a/wire/core/PageTraversal.php +++ b/wire/core/PageTraversal.php @@ -572,9 +572,11 @@ class PageTraversal { * * You can specify an `$options` argument to this method with any of the following: * - * - `pageNum` (int|string): Specify pagination number, or "+" for next pagination, or "-" for previous pagination. - * - `urlSegmentStr` (string): Specify a URL segment string to append. - * - `urlSegments` (array): Specify array of URL segments to append (may be used instead of urlSegmentStr). + * - `pageNum` (int|string|bool): Specify pagination number, "+" for next pagination, "-" for previous pagination, or true for current. + * - `urlSegmentStr` (string|bool): Specify a URL segment string to append, or true (3.0.155+) for current. + * - `urlSegments` (array|bool): Specify regular array of URL segments to append (may be used instead of urlSegmentStr). + * Specify boolean true for current URL segments (3.0.155+). + * Specify associative array (in 3.0.155+) to make both keys and values part of the URL segment string. * - `data` (array): Array of key=value variables to form a query string. * - `http` (bool): Specify true to make URL include scheme and hostname (default=false). * - `language` (Language): Specify Language object to return URL in that Language. @@ -625,9 +627,30 @@ class PageTraversal { $sanitizer = $page->wire('sanitizer'); $language = null; $url = null; + + if($options['urlSegments'] === true || $options['urlSegmentStr'] === true) { + $options['urlSegments'] = $page->wire('input')->urlSegments(); + } + + if($options['pageNum'] === true) { + $options['pageNum'] = $page->wire('input')->pageNum(); + } if(count($options['urlSegments'])) { - $options['urlSegmentStr'] = implode('/', $options['urlSegments']); + $str = ''; + if(is_string($options['urlSegments'][0])) { + // associative array converts to key/value style URL segments + foreach($options['urlSegments'] as $key => $value) { + $str .= "$key/$value/"; + if(is_int($key)) $str = ''; + if($str === '') break; + } + } + if(strlen($str)) { + $options['urlSegmentStr'] = rtrim($str, '/'); + } else { + $options['urlSegmentStr'] = implode('/', $options['urlSegments']); + } } if($options['language'] && $page->wire('modules')->isInstalled('LanguageSupportPageNames')) { @@ -653,7 +676,7 @@ class PageTraversal { if(is_string($options['urlSegmentStr']) && strlen($options['urlSegmentStr'])) { $url = rtrim($url, '/') . '/' . $sanitizer->pagePathNameUTF8(trim($options['urlSegmentStr'], '/')); - if($template->slashUrlSegments === '' || $template->slashUrlSegments) $url .= '/'; + if($template->slashUrlSegments > -1) $url .= '/'; } if($options['pageNum']) {