From 74e6ceba40c2d2428bc4a4c57d8046992577c639 Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Tue, 9 Apr 2024 09:15:27 +1000 Subject: [PATCH] Add support for `Fields::EVENT_DEFINE_COMPATIBLE_FIELD_TYPES` when converting to Matrix, to remove warning about changing Super Table to Matrix fields --- src/SuperTable.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/SuperTable.php b/src/SuperTable.php index 85825a1..c4d25bc 100755 --- a/src/SuperTable.php +++ b/src/SuperTable.php @@ -8,8 +8,10 @@ use Craft; use craft\base\Plugin; +use craft\events\DefineCompatibleFieldTypesEvent; use craft\events\RegisterComponentTypesEvent; use craft\events\RegisterUrlRulesEvent; +use craft\fields\Matrix; use craft\helpers\UrlHelper; use craft\services\Elements; use craft\services\Fields; @@ -45,6 +47,7 @@ public function init(): void $this->_registerVariables(); $this->_registerFieldTypes(); $this->_registerElementTypes(); + $this->_registerCompatibleFieldTypes(); } @@ -72,4 +75,13 @@ private function _registerElementTypes(): void }); } + private function _registerCompatibleFieldTypes(): void + { + Event::on(Fields::class, Fields::EVENT_DEFINE_COMPATIBLE_FIELD_TYPES, function(DefineCompatibleFieldTypesEvent $event) { + if (is_a($event->field, SuperTableField::class)) { + $event->compatibleTypes[] = Matrix::class; + } + }); + } + }