mirror of
				https://github.com/getgrav/grav-plugin-admin.git
				synced 2025-10-31 02:16:26 +01:00 
			
		
		
		
	Merge branch 'feature/multilang' of github.com:getgrav/grav-plugin-admin into 1.10
# Conflicts: # CHANGELOG.md # classes/plugin/AdminController.php # classes/plugin/Twig/AdminTwigExtension.php
This commit is contained in:
		
							
								
								
									
										10
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -1,10 +1,20 @@ | ||||
| # v1.10.0-beta.3 | ||||
| ## 06/24/2019 | ||||
|  | ||||
| 1. [](#new) | ||||
|     * Added `Admin::redirect()` method to allow redirects to be used outside of controllers | ||||
|     * Added `$admin->adminRoute()` method and `admin_route()` twig function to create language aware admin page links | ||||
|     * Renamed `Admin::route()` to `Admin::getCurrentRoute()` and deprecated the old call | ||||
| 1. [](#improved) | ||||
|     * Smarter handling of symlinks in parent field | ||||
|     * Much improved multi-language support for pages | ||||
|     * Admin redirects should now work better with multiple languages enabled | ||||
| 1. [](#bugfix) | ||||
|     * Fixed issue with windows paths in `parent` field [#1699](https://github.com/getgrav/grav-plugin-admin/issues/1699) | ||||
|     * Fixed default language being renamed to `page.en.md` (English) instead of keeping existing `page.md` filename | ||||
|     * Fixed possibility to override already existing translation by `Save As Language` | ||||
|     * Fixed missing default translation if page used plain `.md` file extension without language code | ||||
|     * Fixed wrong translation showing up as page fallback language | ||||
|  | ||||
| # v1.10.0-beta.2 | ||||
| ## 06/21/2019 | ||||
|   | ||||
| @@ -10,6 +10,7 @@ use Grav\Common\GPM\Licenses; | ||||
| use Grav\Common\GPM\Response; | ||||
| use Grav\Common\Grav; | ||||
| use Grav\Common\Helpers\YamlLinter; | ||||
| use Grav\Common\Language\Language; | ||||
| use Grav\Common\Language\LanguageCodes; | ||||
| use Grav\Common\Page\Collection; | ||||
| use Grav\Common\Page\Interfaces\PageInterface; | ||||
| @@ -24,6 +25,8 @@ use Grav\Common\User\Interfaces\UserCollectionInterface; | ||||
| use Grav\Common\User\User; | ||||
| use Grav\Common\Utils; | ||||
| use Grav\Framework\Collection\ArrayCollection; | ||||
| use Grav\Framework\Route\Route; | ||||
| use Grav\Framework\Route\RouteFactory; | ||||
| use Grav\Plugin\Login\Login; | ||||
| use Grav\Plugin\Login\TwoFactorAuth\TwoFactorAuth; | ||||
| use PicoFeed\Parser\MalformedXmlException; | ||||
| @@ -74,8 +77,11 @@ class Admin | ||||
|     /** @var bool */ | ||||
|     public $multilang; | ||||
|  | ||||
|     /** @var string */ | ||||
|     public $language; | ||||
|  | ||||
|     /** @var array */ | ||||
|     public $languages_enabled; | ||||
|     public $languages_enabled = []; | ||||
|  | ||||
|     /** @var Uri $uri */ | ||||
|     protected $uri; | ||||
| @@ -128,27 +134,25 @@ class Admin | ||||
|         $this->session     = $grav['session']; | ||||
|         $this->user        = $grav['user']; | ||||
|         $this->permissions = []; | ||||
|  | ||||
|         /** @var Language $language */ | ||||
|         $language = $grav['language']; | ||||
|  | ||||
|         $this->multilang = $language->enabled(); | ||||
|  | ||||
|         // Load utility class | ||||
|         if ($language->enabled()) { | ||||
|             $this->multilang         = true; | ||||
|         if ($this->multilang) { | ||||
|             $this->language = $language->getLanguage(); | ||||
|             $this->languages_enabled = (array)$this->grav['config']->get('system.languages.supported', []); | ||||
|  | ||||
|             //Set the currently active language for the admin | ||||
|             $language = $this->grav['uri']->param('lang'); | ||||
|             if (!$language) { | ||||
|                 if (!$this->session->admin_lang) { | ||||
|                     $this->session->admin_lang = $this->grav['language']->getLanguage(); | ||||
|             $languageCode = $this->grav['uri']->param('lang'); | ||||
|             if (!$languageCode && !$this->session->admin_lang) { | ||||
|                 $this->session->admin_lang = $language->getLanguage(); | ||||
|             } | ||||
|                 $language = $this->session->admin_lang; | ||||
|             } | ||||
|             $this->grav['language']->setActive($language ?: 'en'); | ||||
|         } else { | ||||
|             $this->grav['language']->setActive('en'); | ||||
|             $this->multilang = false; | ||||
|             $this->language = 'en'; | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -180,6 +184,11 @@ class Admin | ||||
|         return $languages; | ||||
|     } | ||||
|  | ||||
|     public function getLanguage(): string | ||||
|     { | ||||
|         return $this->language; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return the found configuration blueprints | ||||
|      * | ||||
| @@ -276,15 +285,56 @@ class Admin | ||||
|         return Grav::instance()['session']->lastPageRoute ?: self::route(); | ||||
|     } | ||||
|  | ||||
|     public function getAdminRoute(string $path = '', $languageCode = null): Route | ||||
|     { | ||||
|         /** @var Language $language */ | ||||
|         $language = $this->grav['language']; | ||||
|         $languageCode = $languageCode ?? $language->getLanguage(); | ||||
|         $languagePrefix = $language->getLanguageURLPrefix($languageCode); | ||||
|  | ||||
|         $parts = [ | ||||
|             'path' => $path, | ||||
|             'query' => '', | ||||
|             'query_params' => [], | ||||
|             'grav' => [ | ||||
|                 // TODO: Make URL to be /admin/en, not /en/admin. | ||||
|                 'root' => RouteFactory::getRoot() . $languagePrefix . $this->base, | ||||
|                 'language' => '', //$languageCode, | ||||
|                 'route' => ltrim($path, '/'), | ||||
|                 'params' => '' | ||||
|             ], | ||||
|         ]; | ||||
|  | ||||
|         return RouteFactory::createFromParts($parts); | ||||
|     } | ||||
|  | ||||
|     public function adminUrl(string $route = '', $languageCode = null) | ||||
|     { | ||||
|         /** @var string $base_url */ | ||||
|         $baseUrl = $this->grav['base_url']; | ||||
|  | ||||
|         return $baseUrl . $this->getAdminRoute($route, $languageCode); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Static helper method to return current route. | ||||
|      * | ||||
|      * @return string | ||||
|      * @deprecated 1.10 Use $admin->getCurrentRoute() instead | ||||
|      */ | ||||
|     public static function route() | ||||
|     { | ||||
|         user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Admin 1.9.7, use $admin->getCurrentRoute() instead', E_USER_DEPRECATED); | ||||
|  | ||||
|         $admin = Grav::instance()['admin']; | ||||
|  | ||||
|         return $admin->getCurrentRoute(); | ||||
|     } | ||||
|  | ||||
|     public function getCurrentRoute() | ||||
|     { | ||||
|         $pages = Grav::instance()['pages']; | ||||
|         $route = '/' . ltrim(Grav::instance()['admin']->route, '/'); | ||||
|         $route = '/' . ltrim($this->route, '/'); | ||||
|  | ||||
|         /** @var PageInterface $page */ | ||||
|         $page         = $pages->dispatch($route); | ||||
| @@ -298,6 +348,64 @@ class Admin | ||||
|         return $parent_route; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Redirect to the route stored in $this->redirect | ||||
|      * | ||||
|      * Route may or may not be prefixed by /en or /admin or /en/admin. | ||||
|      * | ||||
|      * @param string $redirect | ||||
|      * @param int$redirectCode | ||||
|      */ | ||||
|     public function redirect($redirect, $redirectCode = 303) | ||||
|     { | ||||
|         // No redirect, do nothing. | ||||
|         if (!$redirect) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         $redirect = '/' . ltrim($redirect, '/'); | ||||
|         $base = $this->base; | ||||
|  | ||||
|         // Check if we already have an admin path: /admin. | ||||
|         if (Utils::startsWith($redirect, $base)) { | ||||
|             $this->grav->redirect($redirect, $redirectCode); | ||||
|         } | ||||
|  | ||||
|         if ($this->isMultilang()) { | ||||
|             // Check if URL does not have language prefix. | ||||
|             if (!Utils::pathPrefixedByLangCode($redirect)) { | ||||
|                 /** @var Language $language */ | ||||
|                 $language = $this->grav['language']; | ||||
|  | ||||
|                 // Prefix path with language prefix: /en | ||||
|                 // TODO: Use /admin/en instead of /en/admin in the future. | ||||
|                 $redirect = $language->getLanguageURLPrefix($this->grav['session']->admin_lang) . $base . $redirect; | ||||
|             } else { | ||||
|                 // TODO: Use /admin/en instead of /en/admin in the future. | ||||
|                 //$redirect = preg_replace('`^(/[^/]+)/admin`', '\\1', $redirect); | ||||
|  | ||||
|                 // Check if we already have language prefixed admin path: /en/admin | ||||
|                 $this->grav->redirect($redirect, $redirectCode); | ||||
|             } | ||||
|         } else { | ||||
|             // TODO: Use /admin/en instead of /en/admin in the future. | ||||
|             // Prefix path with /admin | ||||
|             $redirect = $base . $redirect; | ||||
|         } | ||||
|  | ||||
|         $this->grav->redirect($redirect, $redirectCode); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Return true if multilang is active | ||||
|      * | ||||
|      * @return bool True if multilang is active | ||||
|      */ | ||||
|     protected function isMultilang() | ||||
|     { | ||||
|         return count($this->grav['config']->get('system.languages.supported', [])) > 1; | ||||
|     } | ||||
|  | ||||
|     public static function getTempDir() | ||||
|     { | ||||
|         try { | ||||
|   | ||||
| @@ -609,48 +609,12 @@ class AdminBaseController | ||||
|  | ||||
|     /** | ||||
|      * Redirect to the route stored in $this->redirect | ||||
|      * | ||||
|      * Route may or may not be prefixed by /en or /admin or /en/admin. | ||||
|      */ | ||||
|     public function redirect() | ||||
|     { | ||||
|         if (!$this->redirect) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         $base           = $this->admin->base; | ||||
|         $this->redirect = '/' . ltrim($this->redirect, '/'); | ||||
|         $multilang      = $this->isMultilang(); | ||||
|  | ||||
|         $redirect = ''; | ||||
|         if ($multilang) { | ||||
|             // if base path does not already contain the lang code, add it | ||||
|             $langPrefix = '/' . $this->grav['session']->admin_lang; | ||||
|             if (!Utils::startsWith($base, $langPrefix . '/')) { | ||||
|                 $base = $langPrefix . $base; | ||||
|             } | ||||
|  | ||||
|             // now the first 4 chars of base contain the lang code. | ||||
|             // if redirect path already contains the lang code, and is != than the base lang code, then use redirect path as-is | ||||
|             if (Utils::pathPrefixedByLangCode($base) && Utils::pathPrefixedByLangCode($this->redirect) | ||||
|                 && !Utils::startsWith($this->redirect, $base) | ||||
|             ) { | ||||
|                 $redirect = $this->redirect; | ||||
|             } else { | ||||
|                 if (!Utils::startsWith($this->redirect, $base)) { | ||||
|                     $this->redirect = $base . $this->redirect; | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|         } else { | ||||
|             if (!Utils::startsWith($this->redirect, $base)) { | ||||
|                 $this->redirect = $base . $this->redirect; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (!$redirect) { | ||||
|             $redirect = $this->redirect; | ||||
|         } | ||||
|  | ||||
|         $this->grav->redirect($redirect, $this->redirectCode); | ||||
|         $this->admin->redirect($this->redirect, $this->redirectCode); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -11,6 +11,7 @@ use Grav\Common\GPM\GPM as GravGPM; | ||||
| use Grav\Common\GPM\Installer; | ||||
| use Grav\Common\Grav; | ||||
| use Grav\Common\Data; | ||||
| use Grav\Common\Language\Language; | ||||
| use Grav\Common\Page\Interfaces\PageInterface; | ||||
| use Grav\Common\Page\Media; | ||||
| use Grav\Common\Page\Medium\ImageMedium; | ||||
| @@ -1257,10 +1258,7 @@ class AdminController extends AdminBaseController | ||||
|  | ||||
|         $this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info'); | ||||
|  | ||||
|         $multilang    = $this->isMultilang(); | ||||
|         $admin_route  = $this->admin->base; | ||||
|         $redirect_url = '/' . ($multilang ? ($this->grav['session']->admin_lang) : '') . $admin_route . '/' . $this->view; | ||||
|         $this->setRedirect($redirect_url); | ||||
|         $this->setRedirect($this->admin->getAdminRoute("/{$this->view}")->toString()); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| @@ -1364,10 +1362,8 @@ class AdminController extends AdminBaseController | ||||
|  | ||||
|         $multilang = $this->isMultilang(); | ||||
|  | ||||
|         if ($multilang) { | ||||
|             if (!$obj->language()) { | ||||
|                 $obj->language($this->grav['session']->admin_lang); | ||||
|             } | ||||
|         if ($multilang && !$obj->language()) { | ||||
|             $obj->language($this->admin->language); | ||||
|         } | ||||
|         $admin_route = $this->admin->base; | ||||
|  | ||||
| @@ -1548,16 +1544,12 @@ class AdminController extends AdminBaseController | ||||
|  | ||||
|         $data = (array)$this->data; | ||||
|  | ||||
|         if (isset($data['lang'])) { | ||||
|             $language = $data['lang']; | ||||
|         } else { | ||||
|             $language = $this->grav['uri']->param('lang'); | ||||
|         } | ||||
|         $language = $data['lang'] ?? $this->grav['uri']->param('lang'); | ||||
|  | ||||
|         if (isset($data['redirect'])) { | ||||
|             $redirect = 'pages/' . $data['redirect']; | ||||
|             $redirect = '/pages/' . $data['redirect']; | ||||
|         } else { | ||||
|             $redirect = 'pages'; | ||||
|             $redirect = '/pages'; | ||||
|         } | ||||
|  | ||||
|  | ||||
| @@ -1567,8 +1559,7 @@ class AdminController extends AdminBaseController | ||||
|  | ||||
|         $this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info'); | ||||
|  | ||||
|         $admin_route = $this->admin->base; | ||||
|         $this->setRedirect('/' . $language . $admin_route . '/' . $redirect); | ||||
|         $this->setRedirect($this->admin->getAdminRoute($redirect)->toString()); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| @@ -1584,27 +1575,30 @@ class AdminController extends AdminBaseController | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         $data     = (array)$this->data; | ||||
|         $language = $data['lang']; | ||||
|         /** @var Language $language */ | ||||
|         $language = $this->grav['language']; | ||||
|  | ||||
|         if ($language) { | ||||
|             $this->grav['session']->admin_lang = $language ?: 'en'; | ||||
|         $data     = (array)$this->data; | ||||
|         $lang = $data['lang'] ?? null; | ||||
|  | ||||
|         if ($lang) { | ||||
|             $this->grav['session']->admin_lang = $lang ?: 'en'; | ||||
|         } | ||||
|  | ||||
|         $uri = $this->grav['uri']; | ||||
|         $obj = $this->admin->page($uri->route()); | ||||
|         $this->preparePage($obj, false, $language); | ||||
|         $this->preparePage($obj, false, $lang); | ||||
|  | ||||
|         $file = $obj->file(); | ||||
|         if ($file) { | ||||
|             $filename = $this->determineFilenameIncludingLanguage($obj->name(), $language); | ||||
|             $filename = $this->determineFilenameIncludingLanguage($obj->name(), $lang); | ||||
|  | ||||
|             $path  = $obj->path() . DS . $filename; | ||||
|             $aFile = File::instance($path); | ||||
|             $aFile->save(); | ||||
|  | ||||
|             $aPage = new Page(); | ||||
|             $aPage->init(new \SplFileInfo($path), $language . '.md'); | ||||
|             $aPage->init(new \SplFileInfo($path), $lang . '.md'); | ||||
|             $aPage->header($obj->header()); | ||||
|             $aPage->rawMarkdown($obj->rawMarkdown()); | ||||
|             $aPage->template($obj->template()); | ||||
| @@ -1621,7 +1615,9 @@ class AdminController extends AdminBaseController | ||||
|         } | ||||
|  | ||||
|         $this->admin->setMessage($this->admin::translate('PLUGIN_ADMIN.SUCCESSFULLY_SWITCHED_LANGUAGE'), 'info'); | ||||
|         $this->setRedirect('/' . $language . $uri->route()); | ||||
|  | ||||
|         // TODO: better multilanguage support needed. | ||||
|         $this->setRedirect($language->getLanguageURLPrefix($lang) . $uri->route()); | ||||
|  | ||||
|         return true; | ||||
|     } | ||||
| @@ -2449,9 +2445,9 @@ class AdminController extends AdminBaseController | ||||
|      * | ||||
|      * @param PageInterface          $page | ||||
|      * @param bool                   $clean_header | ||||
|      * @param string                 $language | ||||
|      * @param string                 $languageCode | ||||
|      */ | ||||
|     protected function preparePage(PageInterface $page, $clean_header = false, $language = '') | ||||
|     protected function preparePage(PageInterface $page, $clean_header = false, $languageCode = '') | ||||
|     { | ||||
|         $input = (array)$this->data; | ||||
|  | ||||
| @@ -2463,18 +2459,29 @@ class AdminController extends AdminBaseController | ||||
|  | ||||
|         if (isset($input['name']) && !empty($input['name'])) { | ||||
|             $type = strtolower($input['name']); | ||||
|             $page->template($type); | ||||
|             $name = preg_replace('|.*/|', '', $type); | ||||
|             if ($language) { | ||||
|                 $name .= '.' . $language; | ||||
|             } else { | ||||
|  | ||||
|             /** @var Language $language */ | ||||
|             $language = $this->grav['language']; | ||||
|             if ($language->enabled()) { | ||||
|                     $name .= '.' . $language->getLanguage(); | ||||
|                 $languageCode = $languageCode ?: $language->getLanguage(); | ||||
|                 if ($languageCode) { | ||||
|                     $isDefault = $languageCode === $language->getDefault(); | ||||
|                     $includeLang = !$isDefault || (bool)$this->grav['config']->get('system.languages.include_default_lang_file_extension', true); | ||||
|                     if (!$includeLang) { | ||||
|                         // Check if the language specific file exists; use it if it does. | ||||
|                         $includeLang = file_exists("{$page->path()}/{$name}.{$languageCode}.md"); | ||||
|                     } | ||||
|                     // Keep existing .md file if we're updating default language, otherwise always append the language. | ||||
|                     if ($includeLang) { | ||||
|                         $name .= '.' . $languageCode; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             $name .= '.md'; | ||||
|             $page->name($name); | ||||
|             $page->template($type); | ||||
|         } | ||||
|  | ||||
|         // Special case for Expert mode: build the raw, unset content | ||||
|   | ||||
| @@ -9,6 +9,7 @@ use Grav\Common\Language\Language; | ||||
| use Twig\Extension\AbstractExtension; | ||||
| use Twig\TwigFilter; | ||||
| use Twig\TwigFunction; | ||||
| use Grav\Plugin\Admin\Admin; | ||||
|  | ||||
| class AdminTwigExtension extends AbstractExtension | ||||
| { | ||||
| @@ -38,7 +39,8 @@ class AdminTwigExtension extends AbstractExtension | ||||
|     public function getFunctions(): array | ||||
|     { | ||||
|         return [ | ||||
|             new TwigFunction('getPageUrl', [$this, 'getPageUrl'], ['needs_context' => true]), | ||||
|             new TwigFunction('admin_route', [$this, 'adminRouteFunc']), | ||||
|             new TwigFunction('getPageUrl', [$this, 'getPageUrl']), | ||||
|             new TwigFunction('clone', [$this, 'cloneFunc']), | ||||
|         ]; | ||||
|     } | ||||
| @@ -65,21 +67,20 @@ class AdminTwigExtension extends AbstractExtension | ||||
|         return clone $obj; | ||||
|     } | ||||
|  | ||||
|     public function getPageUrl($context, PageInterface $page) | ||||
|     public function adminRouteFunc(string $route = '', string $languageCode = null) | ||||
|     { | ||||
|         $page_route = trim($page->rawRoute(), '/'); | ||||
|         $page_lang = $page->language(); | ||||
|         $base_url = $context['base_url']; | ||||
|         $base_url_simple = $context['base_url_simple']; | ||||
|         $admin_lang = Grav::instance()['session']->admin_lang ?: 'en'; | ||||
|         /** @var Admin $admin */ | ||||
|         $admin = Grav::instance()['admin']; | ||||
|  | ||||
|         if ($page_lang && $page_lang !== $admin_lang) { | ||||
|             $page_url = $base_url_simple . '/' . $page_lang . '/' . $context['admin_route'] . '/pages/' . $page_route; | ||||
|         } else { | ||||
|             $page_url = $base_url . '/pages/' . $page_route; | ||||
|         return $admin->getAdminRoute($route, $languageCode)->toString(true); | ||||
|     } | ||||
|  | ||||
|         return $page_url; | ||||
|     public function getPageUrl(PageInterface $page) | ||||
|     { | ||||
|         /** @var Admin $admin */ | ||||
|         $admin = Grav::instance()['admin']; | ||||
|  | ||||
|         return $admin->getAdminRoute('/pages' . $page->rawRoute(), $page->language())->toString(true); | ||||
|     } | ||||
|  | ||||
|     public static function tuFilter() | ||||
|   | ||||
| @@ -501,6 +501,8 @@ PLUGIN_ADMIN: | ||||
|   PLUGIN_STATUS: "Plugin status" | ||||
|   INCLUDE_DEFAULT_LANG: "Include default language" | ||||
|   INCLUDE_DEFAULT_LANG_HELP: "This will prepend all URLs in the default language with the default language.  e.g. `/en/blog/my-post`" | ||||
|   INCLUDE_DEFAULT_LANG_FILE_EXTENSION: "Include default language in file extension" | ||||
|   INCLUDE_DEFAULT_LANG_HELP_FILE_EXTENSION: "If enabled, it will prepend the default language to the file extension (e.g. `.en.md`). Disable it to keep the default language using `.md` file extension." | ||||
|   PAGES_FALLBACK_ONLY: "Pages fallback only" | ||||
|   PAGES_FALLBACK_ONLY_HELP: "Only 'fallback' to find page content through supported languages, default behavior is to display any language found if active language is missing" | ||||
|   ALLOW_URL_TAXONOMY_FILTERS: "URL Taxonomy Filters" | ||||
|   | ||||
| @@ -10,11 +10,8 @@ | ||||
|     {% set config = twig_vars['config'] %} | ||||
|     {% set separator = config.system.param_sep %} | ||||
|     {% set display_field = config.plugins.admin.pages_list_display_field %} | ||||
|     {% set base_url = twig_vars['base_url_relative'] %} | ||||
|     {% set base_url_relative_frontend = twig_vars['base_url_relative_frontend'] %} | ||||
|     {% set base_url_simple = twig_vars['base_url_simple'] %} | ||||
|     {% set admin_route = twig_vars['admin_route'] %} | ||||
|     {% set admin_lang = twig_vars['admin_lang'] %} | ||||
|     {% set admin = twig_vars['admin'] %} | ||||
|     {% set warn = twig_vars['warn'] %} | ||||
|     {% set uri = twig_vars['uri'] %} | ||||
|  | ||||
| @@ -49,7 +46,7 @@ | ||||
|                             <a href="{{ page_url }}" class="page-edit">{{ page_label|e }}</a> | ||||
|                         </span> | ||||
|                         {% if p.language %} | ||||
|                             <span class="badge lang {% if p.language == admin_lang %}info{% endif %}">{{p.language}}</span> | ||||
|                             <span class="badge lang {% if p.language == admin.language %}info{% endif %}">{{p.language}}</span> | ||||
|                         {% endif %} | ||||
|                         {% if p.home %} | ||||
|                             <span class="page-home"><i class="fa fa-home"></i></span> | ||||
| @@ -60,11 +57,11 @@ | ||||
|                 <span class="page-item__tools"> | ||||
|                     {% if config.plugins.admin.frontend_preview_target != 'inline' %} | ||||
|                         {% set preview_target = config.plugins.admin.frontend_preview_target %} | ||||
|                         {% set preview_html = (base_url_relative_frontend|rtrim('/') ~ (p.home ? '' : p.route)) ?: '/' %} | ||||
|                         {% set preview_link = p.routable ? '<a class="page-view" target="' ~ preview_target ~ '" href="' ~ preview_html ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye"></i></a>' : '' %} | ||||
|                         {% set preview_route = (base_url_relative_frontend|rtrim('/') ~ (p.home ? '' : p.route)) ?: '/' %} | ||||
|                         {% set preview_link = p.routable ? '<a class="page-view" target="' ~ preview_target ~ '" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye"></i></a>' : '' %} | ||||
|                     {% else %} | ||||
|                         {% set preview_html = (base_url|rtrim('/') ~ '/preview' ~ (p.home ? '' : p.route)) ?: '/' %} | ||||
|                         {% set preview_link = p.routable ? '<a class="page-view" href="' ~ preview_html ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye"></i></a>' : '' %} | ||||
|                         {% set preview_route = admin_route('/preview' ~ (p.home ? '' : p.route), 'fi') %} | ||||
|                         {% set preview_link = p.routable ? '<a class="page-view" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye"></i></a>' : '' %} | ||||
|                     {% endif %} | ||||
|                     {{ preview_link|raw }} | ||||
|                     {% if warn %} | ||||
| @@ -87,6 +84,14 @@ | ||||
|  | ||||
| {% if admin.route %} | ||||
|     {% set context = admin.page(true) %} | ||||
|     {# | ||||
|     {% if admin.language != admin.session.admin_lang %} | ||||
|         {% do admin.setMessage('Session language does not match') %} | ||||
|     {% endif %} | ||||
|     #} | ||||
| {% elseif admin.language != admin.session.admin_lang %} | ||||
|     {# Redirect to last set language #} | ||||
|     {% do admin.redirect(admin.adminRoute('/pages', admin.session.admin_lang)) %} | ||||
| {% endif %} | ||||
|  | ||||
| {% if uri.param('new') %} | ||||
| @@ -94,7 +99,7 @@ | ||||
| {%  elseif context %} | ||||
|     {% set mode = 'edit' %} | ||||
|     {% if context.exists %} | ||||
|         {% set page_url = base_url ~ '/pages' ~ (context.header.routes.default ?: context.rawRoute) %} | ||||
|         {% set page_url = admin_route('/pages' ~ (context.header.routes.default ?: context.rawRoute)) %} | ||||
|         {% set exists = true %} | ||||
|         {% set title = (context.exists ? "PLUGIN_ADMIN.EDIT"|tu : "PLUGIN_ADMIN.CREATE"|tu ) ~ " " ~ (context.header.title ?: context.title) %} | ||||
|     {% else %} | ||||
| @@ -107,7 +112,6 @@ | ||||
|  | ||||
| {% set modular = context.modular ? 'modular_' : '' %} | ||||
| {% set warn = config.plugins.admin.warnings.delete_page %} | ||||
| {% set admin_lang = admin.session.admin_lang ?: 'en' %} | ||||
| {% set page_lang = context.language %} | ||||
| {% set type = 'page' %} | ||||
|  | ||||
| @@ -123,19 +127,19 @@ | ||||
| {% endblock %} | ||||
|  | ||||
| {% if config.plugins.admin.frontend_preview_target != 'inline' %} | ||||
|     {% set preview_html = (base_url_relative_frontend|rtrim('/') ~ (context.home ? '' : context.route)) ?: '/' %} | ||||
|     {% set preview_route = (base_url_relative_frontend|rtrim('/') ~ (context.home ? '' : context.route)) ?: '/' %} | ||||
|     {% set preview_target = config.plugins.admin.frontend_preview_target %} | ||||
|     {% set preview_link = context.routable ? '<a class="button" target="' ~ preview_target ~ '" href="' ~ preview_html ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye" style="font-size:18px;margin-right:0;"></i></a>' : '' %} | ||||
|     {% set preview_link = context.routable ? '<a class="button" target="' ~ preview_target ~ '" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye" style="font-size:18px;margin-right:0;"></i></a>' : '' %} | ||||
| {% else %} | ||||
|     {% set preview_html = (base_url|rtrim('/') ~ '/preview' ~ (context.home ? '' : context.route)) ?: '/' %} | ||||
|     {% set preview_link = context.routable ? '<a class="button" href="' ~ preview_html ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye" style="font-size:18px;margin-right:0;"></i></a>' : '' %} | ||||
|     {% set preview_route = admin_route('/preview' ~ (context.home ? '' : context.route)) %} | ||||
|     {% set preview_link = context.routable ? '<a class="button" href="' ~ preview_route ~ '" title="' ~ "PLUGIN_ADMIN.PREVIEW"|tu ~ '"> <i class="fa fa-fw fa-eye" style="font-size:18px;margin-right:0;"></i></a>' : '' %} | ||||
| {% endif %} | ||||
|  | ||||
| {% block titlebar %} | ||||
|  | ||||
|     <div class="button-bar"> | ||||
|         {% if mode == 'list' %} | ||||
|             <a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a> | ||||
|             <a class="button" href="{{ admin_route() }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a> | ||||
|  | ||||
|             {% for key, add_modal in config.plugins.admin.add_modals %} | ||||
|                 {% if add_modal.show_in|defined('bar') == 'bar' %} | ||||
| @@ -168,7 +172,7 @@ | ||||
|                 <div class="button-group"> | ||||
|                     <button type="button" class="button disabled"> | ||||
|                         <i class="fa fa-flag-o"></i> | ||||
|                         {% set langName = admin.siteLanguages[admin_lang] %} | ||||
|                         {% set langName = admin.siteLanguages[admin.language] %} | ||||
|                         {{ langName[:1]|upper ~ langName[1:] }} | ||||
|                     </button> | ||||
|                     {%  if admin.languages_enabled|length > 1 %} | ||||
| @@ -178,7 +182,7 @@ | ||||
|                     <ul class="dropdown-menu language-switcher"> | ||||
|                         {% for langCode in admin.languages_enabled %} | ||||
|                             {% set langName = admin.siteLanguages[langCode] %} | ||||
|                             {% if langCode != admin_lang %} | ||||
|                             {% if langCode != admin.language %} | ||||
|                                 <li><a href="{{ uri.addNonce(base_url_relative ~ theme.slug ~ '/pages/task' ~ config.system.param_sep ~ 'switchlanguage/lang' ~ config.system.param_sep ~ langCode, 'admin-form', 'admin-nonce') }}">{{ langName[:1]|upper ~ langName[1:] }}</a></li> | ||||
|                             {% endif %} | ||||
|                         {% endfor %} | ||||
| @@ -191,23 +195,23 @@ | ||||
|  | ||||
|             {{ preview_link|raw }} | ||||
|  | ||||
|             <a class="button" href="{{ base_url }}/pages" title="{{ "PLUGIN_ADMIN.BACK"|tu }}"><i class="fa fa-reply"></i></a> | ||||
|             <a class="button" href="{{ admin_route('/pages') }}" title="{{ "PLUGIN_ADMIN.BACK"|tu }}"><i class="fa fa-reply"></i></a> | ||||
|  | ||||
|             {% if exists %} | ||||
|                 {% set siblings = context.parent().children() %} | ||||
|  | ||||
|                 {% if not siblings.isFirst(context.path) %} | ||||
|                     {% set sib = siblings.nextSibling(context.path) %} | ||||
|                 {% set sib_url = base_url ~ '/pages' ~ (sib.header.routes.default ?: sib.rawRoute) %} | ||||
|                     {% set sib_url = admin_route('/pages' ~ (sib.header.routes.default ?: sib.rawRoute)) %} | ||||
|                     <a class="button hidden-mobile" href="{{ sib_url }}" title="{{ "PLUGIN_ADMIN.PREVIOUS"|tu }}"><i class="fa fa-chevron-left"></i></a> | ||||
|                 {% endif %} | ||||
|  | ||||
|                 {% if not siblings.isLast(context.path) %} | ||||
|                     {% set sib = siblings.prevSibling(context.path) %} | ||||
|                 {% set sib_url = base_url ~ '/pages' ~ (sib.header.routes.default ?: sib.rawRoute) %} | ||||
|                     {% set sib_url = admin_route('/pages' ~ (sib.header.routes.default ?: sib.rawRoute)) %} | ||||
|                     <a class="button hidden-mobile" href="{{ sib_url }}" title="{{ "PLUGIN_ADMIN.NEXT"|tu }}"><i class="fa fa-chevron-right"></i></a> | ||||
|                 {% endif %} | ||||
|  | ||||
|             {% if exists %} | ||||
|                 <div class="button-group"> | ||||
|                     <button type="button" class="button disabled" href="#modal" data-remodal-target="modal"> | ||||
|                         <i class="fa fa-plus"></i> {{ "PLUGIN_ADMIN.ADD"|tu }} | ||||
| @@ -239,12 +243,13 @@ | ||||
|             <div class="button-group"> | ||||
|                 <button class="button" name="task" value="save" form="blueprints" type="submit"><i class="fa fa-check"></i> {{ "PLUGIN_ADMIN.SAVE"|tu }}</button> | ||||
|                 {% if exists and admin.multilang %} | ||||
|                     {% if context.untranslatedLanguages %} | ||||
|                     {%  set untranslated = context.untranslatedLanguages(true) %} | ||||
|                     {% if untranslated %} | ||||
|                         <button type="button" class="button dropdown-toggle" data-toggle="dropdown"> | ||||
|                             <i class="fa fa-caret-down"></i> | ||||
|                         </button> | ||||
|                         <ul class="dropdown-menu lang-switcher"> | ||||
|                             {% for langCode in context.untranslatedLanguages %} | ||||
|                             {% for langCode in untranslated %} | ||||
|                                 {% set langName = admin.siteLanguages[langCode] %} | ||||
|                                 {% if langCode != page_lang %} | ||||
|                                     <li><button class="button task" name="task" value="saveas" lang="{{langCode}}" form="blueprints" type="submit">{{ "PLUGIN_ADMIN.SAVE_AS"|tu }} {{ langName[:1]|upper ~ langName[1:] }}</button></li> | ||||
| @@ -283,15 +288,15 @@ | ||||
|                             {% if exists %} | ||||
|                                 {{ page_lang }} | ||||
|                             {% else %} | ||||
|                                 {{ admin_lang }} | ||||
|                                 {{ admin.language }} | ||||
|                             {% endif %} | ||||
|                         </button> | ||||
|                         {% if exists and context.translatedLanguages|length > 1 %} | ||||
|                         {% if exists and context.translatedLanguages(false)|length > 1 %} | ||||
|                             <button type="button" class="button dropdown-toggle" data-toggle="dropdown"> | ||||
|                                 <i class="fa fa-caret-down"></i> | ||||
|                             </button> | ||||
|                             <ul class="dropdown-menu language-switcher"> | ||||
|                                 {% for language, route in context.translatedLanguages %} | ||||
|                                 {% for language, route in context.translatedLanguages(false) %} | ||||
|                                     {% if language != page_lang %} | ||||
|                                     <li><button class="task" name="task" value="switchlanguage" lang="{{language}}" redirect="{{context.rawRoute|trim('/')}}" form="blueprints">{{ language }}</button></li> | ||||
|                                     {% endif %} | ||||
| @@ -309,9 +314,9 @@ | ||||
|                 {% set expertText = macro.spanToggle(expertText, maxLen) %} | ||||
|                 <form id="admin-mode-toggle"> | ||||
|                     <div class="switch-toggle switch-grav"> | ||||
|                         <input type="radio" value="normal" data-leave-url="{{ base_url }}/pages/{{ admin.route|trim('/') }}/mode{{ config.system.param_sep }}normal" id="normal" name="mode-switch" class="highlight" {% if admin.session.expert == '0' %} checked="checked"{% endif %}> | ||||
|                         <input type="radio" value="normal" data-leave-url="{{ admin_route('/pages/' ~ admin.route|trim('/') ~ '/mode' ~ config.system.param_sep ~ 'normal') }}" id="normal" name="mode-switch" class="highlight" {% if admin.session.expert == '0' %} checked="checked"{% endif %}> | ||||
|                         <label for="normal">{{ normalText|raw }}</label> | ||||
|                         <input type="radio" value="expert" data-leave-url="{{ base_url }}/pages/{{ admin.route|trim('/') }}/mode{{ config.system.param_sep }}expert" id="expert" name="mode-switch" class="highlight" {% if admin.session.expert == '1' %} checked="checked"{% endif %}> | ||||
|                         <input type="radio" value="expert" data-leave-url="{{ admin_route('/pages/' ~ admin.route|trim('/') ~ '/mode' ~ config.system.param_sep ~ 'expert') }}" id="expert" name="mode-switch" class="highlight" {% if admin.session.expert == '1' %} checked="checked"{% endif %}> | ||||
|                         <label for="expert">{{ expertText|raw }}</label> | ||||
|                         <a></a> | ||||
|                     </div> | ||||
|   | ||||
| @@ -15,7 +15,7 @@ | ||||
|             </li> | ||||
|         {% endfor %} | ||||
|         <li> | ||||
|             <a href="{{ base_url ~ '/tools/backups' }}" class="button">Backups Manager</a> | ||||
|             <a href="{{ admin_route('/tools/backups') }}" class="button">Backups Manager</a> | ||||
|         </li> | ||||
|     </ul> | ||||
| </div> | ||||
|   | ||||
| @@ -1,21 +1,7 @@ | ||||
| {% macro loop(page, depth, twig_vars) %} | ||||
|     {% import _self as self %} | ||||
|  | ||||
|     {% set separator = twig_vars['config'].system.param_sep %} | ||||
|     {% set base_url = twig_vars['base_url_relative'] %} | ||||
|     {% set base_url_simple = twig_vars['base_url_simple'] %} | ||||
|     {% set admin_route = twig_vars['admin_route'] %} | ||||
|     {% set admin_lang = twig_vars['admin_lang'] %} | ||||
|     {% set warn = twig_vars['warn'] %} | ||||
|  | ||||
|     {% for p in page.children() %} | ||||
|         {% set page_route =  p.rawRoute|trim('/') %} | ||||
|         {% if p.language and p.language != admin_lang %} | ||||
|             {% set page_url = base_url_simple ~ '/' ~ p.language ~ '/' ~ admin_route ~ '/pages/' ~ page_route %} | ||||
|         {% else %} | ||||
|             {% set page_url = base_url ~ '/pages/' ~ page_route  %} | ||||
|         {% endif %} | ||||
|  | ||||
|         <li class="page-item" data-nav-id="{{ p.route }}"> | ||||
|             <div class="row"> | ||||
|                 <span {{ p.children(0).count > 0 ? 'data-toggle="children"' : ''}} class="hint--bottom"> | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| <ul class="grav-menu"> | ||||
|     {% for page in pages.children %} | ||||
|     <li class="{{ (admin.route and page.route == context.route) ? 'Selected' : '' }} {{ page.children.count > 0 ? 'hasChildren' : '' }}"> | ||||
|         <a href="{{ base_url_relative }}/pages/{{ page.route|trim('/') }}"><em class="status {{ page.visible ? 'visible' : '' }}"></em>{{ page.menu }}</a> | ||||
|         <a href="{{ admin_route('/pages/' ~ page.route|trim('/')) }}"><em class="status {{ page.visible ? 'visible' : '' }}"></em>{{ page.menu }}</a> | ||||
|         {% if page.children.count > 0 %} | ||||
|         {% include 'partials/page-children.html.twig' with {pages: page} %} | ||||
|         {% endif %} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user