1

I have an entry with a Matrix field, inside this field I have a Super Table as block type. My fields data looks like below:

"title" => "test1"
"matrixHandle" => array:2 [
  0 => array:2 [
    "type" => "sponsorshipRow"
    "fields" => array:2 [
      "sectionTitle" => "blablabla"
      "superTableHandle" => array:5 [
        0 => array:3 [
          "fields" => array:10 [
            "relatedArticle" => 325051
            ...
          ]
        ]
        1 => [...]
  1 => [...]

Then I loop these fields

foreach ($fields as $key => $value) {
    $entry->setFieldValue($key, $value);
}

And last, I save the entry:

Craft::$app->elements->saveElement($entry);

But every data is saved except for the super table block. The super table block is not even created. Any idea please?

1 Answer 1

1

In the super table array, there has to be a type there:

"superTableHandle" => array:5 [
    0 => array:3 [
      "type" => 1//the field's id
      "fields" => array:10 [
        "relatedArticle" => 325051
        ...
      ]
    ]
    1 => [...]

For me, this id is 1. It can be found in database by running this SQL

select * from supertableblocktypes;

But I ran the code below before and found out the field's id is 81 which is not working for me, I don't know why

dd(Craft::$app->fields->getFieldByHandle('matrixHandle')->blockTypeFields);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.