Skip to content

Commit

Permalink
Merge pull request #12614 from craftcms/bugfix/page-trigger
Browse files Browse the repository at this point in the history
Stop overriding the pageTrigger for CP requests
  • Loading branch information
brandonkelly committed Feb 3, 2023
2 parents 041fabe + 000b906 commit ddf5cf5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Improved the performance of the “Generating pending image transforms” queue job. ([#12274](https://github.com/craftcms/cms/issues/12274))
- Added more reserved field handles to avoid conflicts with `craft\base\Element` properties. ([#12577](https://github.com/craftcms/cms/issues/12577))
- Control panel requests no longer override the `pageTrigger` config setting value to `'p'`. ([#12598](https://github.com/craftcms/cms/issues/12598), [#12614](https://github.com/craftcms/cms/pull/12614))
- Fixed field status badge styling in some contexts. ([#12403](https://github.com/craftcms/cms/issues/12403))
- Fixed a bug where exporting elements with multiple field layouts as a CSV file using the “Expanded” export type would result in mismatched column values.
- Fixed a bug where cancelling a conflicting volume folder move would result in the moved folder getting deleted.
Expand All @@ -22,6 +23,7 @@
- Fixed a bug where element indexes could stop showing their loading spinner prematurely if the element listing needed to be reloaded multiple times in rapid succession. ([#12595](https://github.com/craftcms/cms/issues/12595))
- Fixed a bug where element indexes would show show an expand/collapse toggle for structured elements that only had unsaved draft children, which aren’t actually shown. ([#11253](https://github.com/craftcms/cms/issues/11253))
- Added `craft\helpers\Db::escapeForLike()`.
- Added `craft\web\twig\variables\Paginate::$pageTrigger`. ([#12614](https://github.com/craftcms/cms/pull/12614))
- `craft\services\Assets::getAllDescendantFolders()` now has a `$withParent` argument, which can be passed `false` to omit the parent folder from the results. ([#12536](https://github.com/craftcms/cms/issues/12536))
- Deprecated `craft\helpers\DateTimeHelper::timeZoneAbbreviation()`.
- Deprecated `craft\helpers\DateTimeHelper::timeZoneOffset()`.
Expand Down
11 changes: 7 additions & 4 deletions src/services/TemplateCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,22 @@ private function _path(): string
throw new Exception('Not possible to determine the request path for console commands.');
}

if (Craft::$app->getRequest()->getIsCpRequest()) {
$isCpRequest = $request->getIsCpRequest();
if ($isCpRequest) {
$this->_path = 'cp:';
} else {
$this->_path = 'site:';
}

$this->_path .= Craft::$app->getRequest()->getPathInfo();
$this->_path .= $request->getPathInfo();
if (Craft::$app->getDb()->getIsMysql()) {
$this->_path = StringHelper::encodeMb4($this->_path);
}

if (($pageNum = Craft::$app->getRequest()->getPageNum()) != 1) {
$this->_path .= '/' . Craft::$app->getConfig()->getGeneral()->getPageTrigger() . $pageNum;
$pageNum = $request->getPageNum();
if ($pageNum !== 1) {
$pageTrigger = $isCpRequest ? 'p' : Craft::$app->getConfig()->getGeneral()->getPageTrigger();
$this->_path .= sprintf('/%s%s', $pageTrigger, $pageNum);
}

return $this->_path;
Expand Down
8 changes: 1 addition & 7 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,8 @@ public function init()
}
}

if ($this->_isCpRequest) {
// Force 'p' pageTrigger
// (all that really matters is that it doesn't have a trailing slash, but whatever.)
$this->generalConfig->pageTrigger = 'p';
}

// Is this a paginated request?
$pageTrigger = $this->generalConfig->getPageTrigger();
$pageTrigger = $this->_isCpRequest ? 'p' : $this->generalConfig->getPageTrigger();

// Is this query string-based pagination?
if (strpos($pageTrigger, '?') === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/CpAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private function _craftData(): array
'omitScriptNameInUrls' => (bool)$generalConfig->omitScriptNameInUrls,
'orientation' => $orientation,
'pageNum' => $request->getPageNum(),
'pageTrigger' => $generalConfig->getPageTrigger(),
'pageTrigger' => 'p',
'path' => $request->getPathInfo(),
'pathParam' => $generalConfig->pathParam,
'Pro' => Craft::Pro,
Expand Down
27 changes: 23 additions & 4 deletions src/web/twig/variables/Paginate.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,33 @@ public static function create(Paginator $paginator): self
*/
public $totalPages = 0;

/**
* @var string
* @since 3.7.64
*/
public $pageTrigger;

/**
* @var string Base path
* @see getBasePath()
* @see setBasePath()
*/
private $_basePath;

/**
* @inheritdoc
*/
public function init()
{
parent::init();

if (!isset($this->pageTrigger)) {
$this->pageTrigger = Craft::$app->getRequest()->getIsCpRequest()
? 'p'
: Craft::$app->getConfig()->getGeneral()->getPageTrigger();
}
}

/**
* Returns the base path that should be used for pagination URLs.
*
Expand Down Expand Up @@ -110,8 +130,7 @@ public function getPageUrl(int $page)
return null;
}

$pageTrigger = Craft::$app->getConfig()->getGeneral()->getPageTrigger();
$useQueryParam = strpos($pageTrigger, '?') === 0;
$useQueryParam = strpos($this->pageTrigger, '?') === 0;

$path = $this->getBasePath();

Expand All @@ -121,15 +140,15 @@ public function getPageUrl(int $page)
$path .= '/';
}

$path .= $pageTrigger . $page;
$path .= $this->pageTrigger . $page;
}

// Build the URL with the same query string as the current request
$url = UrlHelper::url($path, Craft::$app->getRequest()->getQueryStringWithoutPath());

// If using a query param, append or remove it
if ($useQueryParam) {
$param = trim($pageTrigger, '?=');
$param = trim($this->pageTrigger, '?=');
if ($page != 1) {
$url = UrlHelper::urlWithParams($url, [$param => $page]);
} else {
Expand Down

0 comments on commit ddf5cf5

Please sign in to comment.