diff --git a/CHANGELOG.md b/CHANGELOG.md index 43e5ec716dd..936c7873a96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Craft CMS 5 +## 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)) +- 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 - 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/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 diff --git a/src/elements/conditions/RelatedToConditionRule.php b/src/elements/conditions/RelatedToConditionRule.php index 794b9ca7864..38eea615172 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,14 @@ protected function inputHtml(): string private function _elementTypeOptions(): array { $options = []; - foreach (Craft::$app->getElements()->getAllElementTypes() as $elementType) { + foreach (Craft::$app->getFields()->getRelationalFieldTypes() as $field) { + /** @var string|BaseRelationField $field */ /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - if (!is_subclass_of($elementType, NestedElementInterface::class)) { - $options[] = [ - 'value' => $elementType, - 'label' => $elementType::displayName(), - ]; - } + $elementType = $field::elementType(); + $options[] = [ + 'value' => $elementType, + 'label' => $elementType::displayName(), + ]; } return $options; } 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)]; } } diff --git a/src/services/Fields.php b/src/services/Fields.php index 6ba6a43693c..075e5525743 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; @@ -334,6 +335,25 @@ public function getNestedEntryFieldTypes(): array return $fieldTypes; } + /** + * 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. *