Skip to content

Commit

Permalink
Merge branch 'develop' into 4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Feb 3, 2023
2 parents b9e154c + e3473ed commit ad8c3ed
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added more reserved field handles to avoid conflicts with `craft\base\Element` properties. ([#12577](https://github.com/craftcms/cms/issues/12577))
- Assets’ `alt` properties are now automatically trimmed of leading/trailing whitespace.
- Asset element components in the control panel now include a `data-alt` attribute. ([#12600](https://github.com/craftcms/cms/discussions/12600))
- 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 @@ -32,8 +33,10 @@
- Fixed a bug where asset thumbnails weren’t getting versioned in the control panel, unless the `revAssetUrls` config setting was enabled. ([#12603](https://github.com/craftcms/cms/issues/12603))
- Fixed a bug where entry relations could be lost when switching entry types, for relational fields that didn’t exist on the prior entry type. ([#12592](https://github.com/craftcms/cms/issues/12592))
- Fixed a bug where Matrix blocks weren’t getting duplicated to other sites when first editing an unpublished draft. ([#11366](https://github.com/craftcms/cms/issues/11366))
- 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\Assets::revUrl()`.
- Added `craft\helpers\Db::escapeForLike()`.
- Added `craft\web\twig\variables\Paginate::$pageTrigger`. ([#12614](https://github.com/craftcms/cms/pull/12614))
- `craft\helpers\Assets::revParams()` no longer takes the `revAssetUrls` config setting into account. That should be factored in by whatever is calling it.
- `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))
- `craft\services\Matrix::duplicateBlocks()` now has a `$force` argument.
Expand Down
7 changes: 7 additions & 0 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,13 @@ class GeneralConfig extends BaseConfig
* CRAFT_OMIT_SCRIPT_NAME_IN_URLS=1
* ```
* :::
* ```
*
* ::: tip
* Even when this is set to `true`, the script name could still be included in some action URLs.
* If you want to ensure that `index.php` is fully omitted from **all** generated URLs, set the <config4:pathParam>
* config setting to `null`.
* :::
*
* @group Routing
*/
Expand Down
11 changes: 7 additions & 4 deletions src/services/TemplateCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,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
1 change: 1 addition & 0 deletions src/templates/_elements/tableview/elements.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.status(null)
.drafts(null)
.draftOf(false)
.savedDraftsOnly()
.count()
: 0 %}
{% set elementTitle = element.title ?: element.id %}
Expand Down
8 changes: 1 addition & 7 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,8 @@ public function init(): void
}
}

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 (str_starts_with($pageTrigger, '?')) {
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 @@ -415,7 +415,7 @@ private function _craftData(): array
'omitScriptNameInUrls' => $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 @@ -68,13 +68,33 @@ public static function create(Paginator $paginator): self
*/
public int $totalPages = 0;

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

/**
* @var string Base path
* @see getBasePath()
* @see setBasePath()
*/
private string $_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 @@ -111,8 +131,7 @@ public function getPageUrl(int $page): ?string
return null;
}

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

$path = $this->getBasePath();

Expand All @@ -122,15 +141,15 @@ public function getPageUrl(int $page): ?string
$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 ad8c3ed

Please sign in to comment.