-
Hey, I'm using fixtures for unit testing / Codeception. It works well with normal matrix fields, but now I added a Super Table field to a matrix block I have ...
Is it possible to fill this field via fixtures - or is this not supported? I tried with 'myMatrixField' => [
'new1' => [
'type' => 'myBlock',
'fields' => [
'componentIds' => [
[
'componentId' => 'page-area-main-catalogs',
]
],
// beware: super table involved here ;) https://verbb.io/craft-plugins/super-table/docs/v2/template-guides/php-example
'images' => [
[
'image' => $image,
'linkUrl' => 'https://example.com/katalog-2023',
]
],
],
]
], I currently get I also saw https://verbb.io/craft-plugins/super-table/docs/v2/template-guides/php-example - I could set the block id Thanks very much for any hints! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Update: I don't need to rely on Fixtures - I could also save it programmatically in my test. I saw https://craftcms.stackexchange.com/questions/31055/saving-a-supertable-field-within-a-matrix-field, but I'm not sure how to adopt it to my use case. What seems to be missing for me is how to get the correct field id for $matrixField = Craft::$app->getFields()->getFieldByHandle('myMatrixField');
$matrixBlockTypes = Craft::$app->matrix->getBlockTypesByFieldId($matrixField->id);
// Loop through the block types to find the desired block type --> only one currently
foreach ($matrixBlockTypes as $matrixBlockType) {
// Returns craft\fieldlayoutelements\CustomField --> no id set?
$superTableField = $matrixBlockType->getFieldLayout()->getField('images');
// ERROR: ->id can't be retrieved 🤔
$blockTypes = SuperTable::$plugin->getService()->getBlockTypesByFieldId($superTableField->id);
$blockType = $blockTypes[0];
$superTableData['new1'] = [
'type' => $blockType->id,
'enabled' => true,
'fields' => [
'fieldOne' => 'Some string or data',
'fieldTwo' => '12'
]
];
// save entry with new data ... |
Beta Was this translation helpful? Give feedback.
Okay, one step further - I needed
$superTableField = $matrixBlockType->getFieldLayout()->getFieldByHandle('images');
. Seems to work now 🎉