Skip to content

Commit

Permalink
Merge branch '5.x' into 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed May 23, 2024
2 parents b61028a + 916d318 commit 60f2f51
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions src/elements/conditions/RelatedToConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>|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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Typecast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<BaseRelationField>[]
* @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.
*
Expand Down

0 comments on commit 60f2f51

Please sign in to comment.