From bae44f93ce7586a19ff5a10d0060738f4a4618b3 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 3 May 2024 13:48:32 -0400 Subject: [PATCH] Update Page::editUrl() method to support a 'vars' (array) option that contains additional query string variables that it should bundle in to returned URL --- wire/core/Page.php | 1 + wire/core/PageTraversal.php | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wire/core/Page.php b/wire/core/Page.php index a5a3c68c..b6de0fc2 100644 --- a/wire/core/Page.php +++ b/wire/core/Page.php @@ -2860,6 +2860,7 @@ class Page extends WireData implements \Countable, WireMatchable { * - `http` (bool): True to force scheme and hostname in URL (default=auto detect). * - `language` (Language|bool): Optionally specify Language to start editor in, or boolean true to force current user language. * - `find` (string): Name of field to find in the editor (3.0.151+) + * - `vars` (array): Additional variables to include in query string (3.0.239+) * @return string URL for editing this page * */ diff --git a/wire/core/PageTraversal.php b/wire/core/PageTraversal.php index 34230601..3b80ebec 100644 --- a/wire/core/PageTraversal.php +++ b/wire/core/PageTraversal.php @@ -852,6 +852,7 @@ class PageTraversal { * - `http` (bool): True to force scheme and hostname in URL (default=auto detect). * - `language` (Language|bool): Optionally specify Language to start editor in, or boolean true to force current user language. * - `find` (string): Name of field to find in the editor (3.0.151+) + * - `vars` (array): Additional variables to include in query string (3.0.239+) * @return string URL for editing this page * */ @@ -862,6 +863,7 @@ class PageTraversal { $https = $adminTemplate && ($adminTemplate->https > 0) && !$config->noHTTPS; $url = ($https && !$config->https) ? 'https://' . $config->httpHost : ''; $url .= $config->urls->admin . "page/edit/?id=$page->id"; + $optionsArray = is_array($options) ? $options : array(); if($options === true || (is_array($options) && !empty($options['http']))) { if(strpos($url, '://') === false) { @@ -872,18 +874,22 @@ class PageTraversal { $languages = $page->wire()->languages; if($languages) { $language = $page->wire()->user->language; - if(empty($options['language'])) { + if(empty($optionsArray['language'])) { if($page->wire()->page->template->id == $adminTemplate->id) $language = null; - } else if($options['language'] instanceof Page) { - $language = $options['language']; - } else if($options['language'] !== true) { - $language = $languages->get($options['language']); + } else if($optionsArray['language'] instanceof Page) { + $language = $optionsArray['language']; + } else if($optionsArray['language'] !== true) { + $language = $languages->get($optionsArray['language']); } if($language && $language->id) $url .= "&language=$language->id"; } $version = (int) ((string) $page->get('_version|_repeater_version')); if($version) $url .= "&version=$version"; + + if(!empty($optionsArray['vars'])) { + $url .= '&' . http_build_query($optionsArray['vars']); + } $append = $page->wire()->session->getFor($page, 'appendEditUrl');