Extract Matrix's entries to Section's entries with the same fields: how? #16774
-
Hi! I have the following use case:
After a while, I have too many team members and the site is now translated into many different languages and I'd like to be able to edit the team member individually so that the same changes can be replicated automatically in the different languages (8 sites, 2 languages = sometimes the changes need to be re-done 8 times because some other content can't be propagated by language automatically, but the team members could). My question is: since matrix fields now create entries under the hood, is there a recommended / best way to extract them to their own section after the fact? I would create a structured section "Team members" with the same entry type, all the fields would be the same. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I think there should be functionality for moving entries between matrix fields and sections, in both directions! I was hoping that would be the case when moving entries beween sections was enabled, but apparently it wasn't. I presume one reason for not having implementing this is the UI? In such case I think a two-step approach with "cut and paste" logic would be clean enough, so as to avoid having to drill down to/from matrix entries in a modal. |
Beta Was this translation helpful? Give feedback.
-
There’s no built-in functionality for this, but you could make it possible yourself via a custom module + CLI command, using the following code: use craft\elements\Entry;
use craft\helpers\Db;
$entries = Entry::find()->field('myMatrixField');
$section = Craft::$app->entries->getSectionByHandle('mySection');
foreach (Db::each($entries) as $entry) {
Craft::$app->elements->duplicateElement($entry, [
'fieldId' => null,
'owner' => null,
'primaryOwner' => null,
'sectionId' => $section->id,
]);
} |
Beta Was this translation helpful? Give feedback.
There’s no built-in functionality for this, but you could make it possible yourself via a custom module + CLI command, using the following code: