From 8682df2e32444163d1cd39d99cd789bba1622054 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 21 Mar 2016 11:02:58 +0100 Subject: [PATCH] Add URI::baseIncludingLanguage() Return the base relative URL including the language prefix, or the base relative url if multilanguage is not enabled --- system/src/Grav/Common/Uri.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index 0c708ca85..8b6a0aaf7 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -601,6 +601,27 @@ class Uri return $this->base; } + /** + * Return the base relative URL including the language prefix + * or the base relative url if multilanguage is not enabled + * + * @return String The base of the URI + */ + public function baseIncludingLanguage() + { + $grav = Grav::instance(); + + // Link processing should prepend language + $language = $grav['language']; + $language_append = ''; + if ($language->enabled()) { + $language_append = $language->getLanguageURLPrefix(); + } + + $base = $grav['base_url_relative']; + return rtrim($base . $grav['pages']->base(), '/') . $language_append; + } + /** * Return root URL to the site. *