1
1
<?php
2
2
namespace verbb \supertable \services ;
3
3
4
+ use craft \db \Table ;
4
5
use verbb \supertable \elements \db \SuperTableBlockQuery ;
5
6
use verbb \supertable \elements \SuperTableBlockElement ;
6
7
use verbb \supertable \errors \SuperTableBlockTypeNotFoundException ;
@@ -312,20 +313,17 @@ public function handleChangedBlockType(ConfigEvent $event)
312
313
return ;
313
314
}
314
315
315
- ProjectConfigHelper::ensureAllFieldsProcessed ();
316
-
317
- // Ensure all Matrix blocks are processed
318
- $ projectConfig = Craft::$ app ->getProjectConfig ();
319
- $ allBlocks = $ projectConfig ->get (\craft \services \Matrix::CONFIG_BLOCKTYPE_KEY , true ) ?? [];
320
-
321
- foreach ($ allBlocks as $ blockUid => $ blockData ) {
322
- $ projectConfig ->processConfigChanges (\craft \services \Matrix::CONFIG_BLOCKTYPE_KEY . '. ' . $ blockUid );
323
- }
324
-
325
316
$ blockTypeUid = $ event ->tokenMatches [0 ];
326
317
$ data = $ event ->newValue ;
327
318
$ previousData = $ event ->oldValue ;
328
319
320
+ // Make sure the field has been synced
321
+ $ fieldId = Db::idByUid (Table::FIELDS , $ data ['field ' ]);
322
+ if ($ fieldId === null ) {
323
+ Craft::$ app ->getProjectConfig ()->defer ($ event , [$ this , __FUNCTION__ ]);
324
+ return ;
325
+ }
326
+
329
327
$ fieldsService = Craft::$ app ->getFields ();
330
328
$ contentService = Craft::$ app ->getContent ();
331
329
@@ -342,7 +340,7 @@ public function handleChangedBlockType(ConfigEvent $event)
342
340
$ blockTypeRecord = $ this ->_getBlockTypeRecord ($ blockTypeUid );
343
341
344
342
// Set the basic info on the new block type record
345
- $ blockTypeRecord ->fieldId = Db:: idByUid ( ' {{%fields}} ' , $ data [ ' field ' ]) ;
343
+ $ blockTypeRecord ->fieldId = $ fieldId ;
346
344
$ blockTypeRecord ->uid = $ blockTypeUid ;
347
345
348
346
// Make sure that alterations, if any, occur in the correct context.
0 commit comments