Skip to content

Commit

Permalink
Merge branch '5.x' into 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 29, 2024
2 parents 715b7c4 + 7a8018d commit d17d37a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## Unreleased

- Craft now sends `X-Robots-Tag: none` headers for preview requests. ([#15612](https://github.com/craftcms/cms/pull/15612), [#15586](https://github.com/craftcms/cms/issues/15586))
- Fixed a SQL error that occurred when running the `db/convert-charset` command if there were any custom database views or sequences. ([#15598](https://github.com/craftcms/cms/issues/15598))
- Fixed a bug where `craft\helpers\Db::supportsTimeZones()` could return `false` on databases that supported time zone conversion. ([#15592](https://github.com/craftcms/cms/issues/15592))
- Fixed a bug where tabs within field layout designers weren’t always getting positioned correctly when wrapped. ([#15590](https://github.com/craftcms/cms/issues/15590))
- Fixed a bug where editable table rows’ action buttons were misaligned for newly-created rows. ([#15602](https://github.com/craftcms/cms/issues/15602))
- Fixed a bug where relational fields’ element query results weren’t limited to the selected relations if the `id` param was overridden. ([#15570](https://github.com/craftcms/cms/issues/15570))
- Fixed a bug where ordering element queries by textual custom fields would factor in character marks. ([#15609](https://github.com/craftcms/cms/issues/15609))

## 5.3.6 - 2024-08-26

Expand Down
14 changes: 12 additions & 2 deletions src/base/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,15 +816,25 @@ public function getPreviewHtml(mixed $value, ElementInterface $element): string
*/
public function getSortOption(): array
{
if (static::dbType() === null || !isset($this->layoutElement)) {
$dbType = static::dbType();
if ($dbType === null || !isset($this->layoutElement)) {
throw new NotSupportedException('getSortOption() not supported by ' . $this->name);
}

$orderBy = $this->getValueSql();

// for mysql, we have to make sure text column type is cast to char, otherwise it won't be sorted correctly
// see https://github.com/craftcms/cms/issues/15609
$db = Craft::$app->getDb();
if ($db->getIsMysql() && Db::parseColumnType($dbType) === Schema::TYPE_TEXT) {
$orderBy = "CAST($orderBy AS CHAR(255))";
}

// The attribute name should match the table attribute name,
// per ElementSources::getTableAttributesForFieldLayouts()
return [
'label' => Craft::t('site', $this->name),
'orderBy' => $this->getValueSql(),
'orderBy' => $orderBy,
'attribute' => isset($this->layoutElement->handle)
? "fieldInstance:{$this->layoutElement->uid}"
: "field:$this->uid",
Expand Down
12 changes: 9 additions & 3 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use craft\base\NestedElementInterface;
use craft\base\RelationalFieldInterface;
use craft\behaviors\EventBehavior;
use craft\db\FixedOrderExpression;
use craft\db\Query;
use craft\db\Table as DbTable;
use craft\elements\conditions\ElementCondition;
Expand Down Expand Up @@ -674,9 +675,14 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed
->siteId($this->targetSiteId($element));

if (is_array($value)) {
$query
->id(array_values(array_filter($value)))
->fixedOrder();
$value = array_values(array_filter($value));
if (!empty($value)) {
$query
->andWhere(['elements.id' => $value])
->orderBy([new FixedOrderExpression('elements.id', $value, Craft::$app->getDb())]);
} else {
$query->andWhere('0 = 1');
}
} elseif ($value === null && $element?->id && $this->isFirstInstance($element)) {
// If $value is null, the element + field haven’t been saved since updating to Craft 5.3+,
// or since the field was added to the field layout. So only actually look at the `relations` table
Expand Down
1 change: 1 addition & 0 deletions src/web/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public function handleRequest($request, bool $skipSpecialHandling = false): Base
$generalConfig->disallowRobots ||
$request->getIsCpRequest() ||
$request->getToken() !== null ||
$request->getIsPreview() ||
($request->getIsActionRequest() && !($request->getIsLoginRequest() && $request->getIsGet()))
) {
$headers->set('X-Robots-Tag', 'none');
Expand Down

0 comments on commit d17d37a

Please sign in to comment.