This commit is contained in:
Bastian Allgeier
2020-07-07 12:40:13 +02:00
parent 5f025ac2c2
commit f79d2e960c
176 changed files with 10532 additions and 5343 deletions

View File

@@ -3,7 +3,6 @@
namespace Kirby\Cms;
use Kirby\Http\Url as BaseUrl;
use Kirby\Toolkit\Str;
/**
* The `Url` class extends the
@@ -61,36 +60,10 @@ class Url extends BaseUrl
*/
public static function to(string $path = null, $options = null): string
{
$kirby = App::instance();
$language = null;
$kirby = App::instance();
// get language from simple string option
if (is_string($options) === true) {
$language = $options;
$options = null;
}
// get language from array
if (is_array($options) === true && isset($options['language']) === true) {
$language = $options['language'];
unset($options['language']);
}
// get a language url for the linked page, if the page can be found
if ($kirby->multilang() === true) {
$parts = Str::split($path, '#');
if ($page = page($parts[0] ?? null)) {
$path = $page->url($language);
if (isset($parts[1]) === true) {
$path .= '#' . $parts[1];
}
}
}
return $kirby->component('url')($kirby, $path, $options, function (string $path = null, $options = null) {
return parent::to($path, $options);
return $kirby->component('url')($kirby, $path, $options, function (string $path = null, $options = null) use ($kirby) {
return $kirby->nativeComponent('url')($kirby, $path, $options);
});
}
}