Add $dropIndex parameter to Pico::getPageUrl() method
This allows one to prevent Pico from removing the last "index" path component. Example use case: Pico's official admin plugin. We must distinguish between "content/sub.md" and "content/sub/index.md", otherwise it wouldn't be possible to edit both pages.
This commit is contained in:
parent
848e28b7e6
commit
aa1bc077a7
@ -1424,9 +1424,11 @@ class Pico
|
|||||||
* @param string $page identifier of the page to link to
|
* @param string $page identifier of the page to link to
|
||||||
* @param array|string $queryData either an array containing properties to
|
* @param array|string $queryData either an array containing properties to
|
||||||
* create a URL-encoded query string from, or a already encoded string
|
* create a URL-encoded query string from, or a already encoded string
|
||||||
|
* @param boolean $dropIndex when the last path component is "index",
|
||||||
|
* then passing TRUE (default) leads to removing this path component
|
||||||
* @return string URL
|
* @return string URL
|
||||||
*/
|
*/
|
||||||
public function getPageUrl($page, $queryData = null)
|
public function getPageUrl($page, $queryData = null, $dropIndex = true)
|
||||||
{
|
{
|
||||||
if (is_array($queryData)) {
|
if (is_array($queryData)) {
|
||||||
$queryData = http_build_query($queryData, '', '&');
|
$queryData = http_build_query($queryData, '', '&');
|
||||||
@ -1438,6 +1440,7 @@ class Pico
|
|||||||
}
|
}
|
||||||
|
|
||||||
// drop "index"
|
// drop "index"
|
||||||
|
if ($dropIndex) {
|
||||||
if ($page === 'index') {
|
if ($page === 'index') {
|
||||||
$page = '';
|
$page = '';
|
||||||
} elseif (($pagePathLength = strrpos($page, '/')) !== false) {
|
} elseif (($pagePathLength = strrpos($page, '/')) !== false) {
|
||||||
@ -1445,6 +1448,7 @@ class Pico
|
|||||||
$page = substr($page, 0, $pagePathLength);
|
$page = substr($page, 0, $pagePathLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($queryData)) {
|
if (!empty($queryData)) {
|
||||||
$queryData = ($this->isUrlRewritingEnabled() || empty($page)) ? '?' . $queryData : '&' . $queryData;
|
$queryData = ($this->isUrlRewritingEnabled() || empty($page)) ? '?' . $queryData : '&' . $queryData;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user