1

Is it possible to add blocks to a Matrix field in an Entry using Feed Me without overwriting existing blocks? I know how to add multiple blocks at once with a single JSON file, but I won't have things in one file and they will need to be updated over time, and grouping them into one file isn't practical in this instance.

In other words, if I have a Matrix field block called Awards, and entries will accumulate multiple Awards over time, each time Adding a new Awards block without removing the older Award blocks. Currently when I try this in Feed Me it just wipes the field clean and adds the new one and deleting any previous entries.

1

In general, Matrix fields support delta saves, so you can mix existing blocks with new blocks when saving matrix fields. This is documented here. Retaining existing blocks involves passing a sortOrder to the field which includes the IDs of all existing blocks you want to keep as well as an identifier for the newly created blocks.

Adding new blocks programmatically can look something like this:

$existingMatrixBlocks = $entry->getFieldValue('my_matrix_field')->ids();
$newMatrixBlocks = [
    'new:1' => ['type' => 'copy', 'fields' => ['text' => 'Lorem Ipsum']],
    'new:2' => ['type' => 'copy', 'fields' => ['text' => 'Dolor Sit']],
];
$newSortOrder = array_merge($existingMatrixBlocks, array_keys($newMatrixBlocks));

$entry->setFieldValue('my_matrix_field', [
    'sortOrder' => $newSortOrder,
    'blocks' => $newMatrixBlocks,
]);

However, I don't think you can do this using Feed Me's interface alone. You might be able to use Event Hooks though to modify the data to be saved accordingly. Or build a custom importer that does the same thing.

2

As far as I know, this is not possible at the moment. You would need to build a custom importer and re-post existing block IDs as part of the sortOrder array.

See more in the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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