From dd1bd2e02f760f362e95bec8b5a4e8ea2e62a84c Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 22 May 2024 15:46:05 -0700 Subject: [PATCH 1/5] Definitely fix #14618 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It may not look like much, but this is a €150 commit. --- CHANGELOG.md | 4 ++++ src/helpers/Typecast.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43e5ec716dd..7f55028ab66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 5 +## Unreleased + +- Fixed a bug where `craft\helpers\Typecast::properties()` wasn’t typecasting numeric strings to ints for `int|string|null` properties. ([#14618](https://github.com/craftcms/cms/issues/14618)) + ## 5.1.5 - 2024-05-22 - Scalar element queries now set `$select` to the scalar expression, and `$orderBy`, `$limit`, and `$offset` to `null`, on the element query. ([#15001](https://github.com/craftcms/cms/issues/15001)) diff --git a/src/helpers/Typecast.php b/src/helpers/Typecast.php index 2e12f7aab72..fb031da2195 100644 --- a/src/helpers/Typecast.php +++ b/src/helpers/Typecast.php @@ -169,7 +169,7 @@ private static function _propertyType(string $class, string $property): array|fa return [self::TYPE_INT_FLOAT, in_array(self::TYPE_NULL, $names)]; } // Special case for int|string - if ($names === [self::TYPE_INT, self::TYPE_STRING] || $names === [self::TYPE_INT, self::TYPE_STRING, self::TYPE_NULL]) { + if ($names === [self::TYPE_INT, self::TYPE_STRING] || $names === [self::TYPE_INT, self::TYPE_NULL, self::TYPE_STRING]) { return [self::TYPE_INT_STRING, in_array(self::TYPE_NULL, $names)]; } } From 750bc0045110fd8be9c2bedc28c5826f53126299 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Thu, 23 May 2024 13:48:42 +0100 Subject: [PATCH 2/5] allow entries and product variants in related to rules --- .../conditions/RelatedToConditionRule.php | 18 ++++++++---------- src/services/Fields.php | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/elements/conditions/RelatedToConditionRule.php b/src/elements/conditions/RelatedToConditionRule.php index 794b9ca7864..9388b51a22a 100644 --- a/src/elements/conditions/RelatedToConditionRule.php +++ b/src/elements/conditions/RelatedToConditionRule.php @@ -5,9 +5,9 @@ use Craft; use craft\base\conditions\BaseElementSelectConditionRule; use craft\base\ElementInterface; -use craft\base\NestedElementInterface; use craft\elements\db\ElementQueryInterface; use craft\elements\Entry; +use craft\fields\BaseRelationField; use craft\helpers\Cp; use craft\helpers\Html; use craft\helpers\UrlHelper; @@ -94,15 +94,13 @@ protected function inputHtml(): string private function _elementTypeOptions(): array { $options = []; - foreach (Craft::$app->getElements()->getAllElementTypes() as $elementType) { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - if (!is_subclass_of($elementType, NestedElementInterface::class)) { - $options[] = [ - 'value' => $elementType, - 'label' => $elementType::displayName(), - ]; - } + /** @var string|BaseRelationField $field */ + foreach (Craft::$app->getFields()->getAllRelationalFieldTypes() as $field) { + $elementType = $field::elementType(); + $options[] = [ + 'value' => $elementType, + 'label' => $elementType::displayName(), + ]; } return $options; } diff --git a/src/services/Fields.php b/src/services/Fields.php index d6a62e85667..aa20576294e 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -27,6 +27,7 @@ use craft\fieldlayoutelements\CustomField; use craft\fields\Addresses as AddressesField; use craft\fields\Assets as AssetsField; +use craft\fields\BaseRelationField; use craft\fields\Categories as CategoriesField; use craft\fields\Checkboxes; use craft\fields\Color; @@ -1395,6 +1396,24 @@ public function getTableData(int $page, int $limit, ?string $searchTerm): array return [$pagination, $tableData]; } + /** + * Returns all available relational field type classes. + * + * @return string[] The available relational field type classes + * @phpstan-return class-string[] + */ + public function getAllRelationalFieldTypes(): array + { + $relationalFields = []; + foreach ($this->getAllFieldTypes() as $fieldClass) { + if (is_subclass_of($fieldClass, BaseRelationField::class)) { + $relationalFields[] = $fieldClass; + } + } + + return $relationalFields; + } + /** * Returns the array of sql "like" params to be used in the 'where' param for the query. * From a41e593e6f7041e8ecaab500cb6b0614283d445b Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 23 May 2024 16:12:24 -0700 Subject: [PATCH 3/5] Cleanup --- .../conditions/RelatedToConditionRule.php | 5 ++- src/services/Fields.php | 37 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/elements/conditions/RelatedToConditionRule.php b/src/elements/conditions/RelatedToConditionRule.php index 9388b51a22a..38eea615172 100644 --- a/src/elements/conditions/RelatedToConditionRule.php +++ b/src/elements/conditions/RelatedToConditionRule.php @@ -94,8 +94,9 @@ protected function inputHtml(): string private function _elementTypeOptions(): array { $options = []; - /** @var string|BaseRelationField $field */ - foreach (Craft::$app->getFields()->getAllRelationalFieldTypes() as $field) { + foreach (Craft::$app->getFields()->getRelationalFieldTypes() as $field) { + /** @var string|BaseRelationField $field */ + /** @var string|ElementInterface $elementType */ $elementType = $field::elementType(); $options[] = [ 'value' => $elementType, diff --git a/src/services/Fields.php b/src/services/Fields.php index aa20576294e..13b5e30663e 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -330,6 +330,25 @@ public function getNestedEntryFieldTypes(): array return $event->types; } + /** + * Returns all available relational field type classes. + * + * @return string[] The available relational field type classes + * @phpstan-return class-string[] + * @since 5.1.6 + */ + public function getRelationalFieldTypes(): array + { + $relationalFields = []; + foreach ($this->getAllFieldTypes() as $fieldClass) { + if (is_subclass_of($fieldClass, BaseRelationField::class)) { + $relationalFields[] = $fieldClass; + } + } + + return $relationalFields; + } + /** * Creates a field with a given config. * @@ -1396,24 +1415,6 @@ public function getTableData(int $page, int $limit, ?string $searchTerm): array return [$pagination, $tableData]; } - /** - * Returns all available relational field type classes. - * - * @return string[] The available relational field type classes - * @phpstan-return class-string[] - */ - public function getAllRelationalFieldTypes(): array - { - $relationalFields = []; - foreach ($this->getAllFieldTypes() as $fieldClass) { - if (is_subclass_of($fieldClass, BaseRelationField::class)) { - $relationalFields[] = $fieldClass; - } - } - - return $relationalFields; - } - /** * Returns the array of sql "like" params to be used in the 'where' param for the query. * From c9bdb80217bc948227f4b8ed70c8892715e81ff6 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 23 May 2024 16:13:48 -0700 Subject: [PATCH 4/5] Release notes [ci skip] --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f55028ab66..78d3e3ea71e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## Unreleased +- Added `craft\services\Fields::getRelationalFieldTypes()`. - Fixed a bug where `craft\helpers\Typecast::properties()` wasn’t typecasting numeric strings to ints for `int|string|null` properties. ([#14618](https://github.com/craftcms/cms/issues/14618)) +- Fixed a bug where “Related To” conditions weren’t allowing entries to be selected. ([#15058](https://github.com/craftcms/cms/issues/15058)) ## 5.1.5 - 2024-05-22 From 916d3185a79a940d0d5d11adcf8b86c973a065ca Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 23 May 2024 16:17:09 -0700 Subject: [PATCH 5/5] Finish 5.1.6 --- CHANGELOG.md | 2 +- src/config/app.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78d3e3ea71e..936c7873a96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Release Notes for Craft CMS 5 -## Unreleased +## 5.1.6 - 2024-05-23 - Added `craft\services\Fields::getRelationalFieldTypes()`. - Fixed a bug where `craft\helpers\Typecast::properties()` wasn’t typecasting numeric strings to ints for `int|string|null` properties. ([#14618](https://github.com/craftcms/cms/issues/14618)) diff --git a/src/config/app.php b/src/config/app.php index e182cba8263..8c2c895da1e 100644 --- a/src/config/app.php +++ b/src/config/app.php @@ -3,7 +3,7 @@ return [ 'id' => 'CraftCMS', 'name' => 'Craft CMS', - 'version' => '5.1.5', + 'version' => '5.1.6', 'schemaVersion' => '5.0.0.20', 'minVersionRequired' => '4.4.0', 'basePath' => dirname(__DIR__), // Defines the @app alias