1

I'm working on importing a database and I was looking at some of the available import plugins. However I am unable to figure out how to import a body field (just a string) into a Matrix block.

Old database entry structure (non-Crafty)

  • title
  • description
  • body

New database entry structure (Crafty)

  • title
  • description
  • matrix [body, image, gallery, etc]

Does anyone have experience with this? Any advice?

1 Answer 1

3

Nevermind. Clearbold's Craft Import plugin has the starting code for it.

// new entry
$entry = new EntryModel();
$entry->sectionId = 1;
$entry->typeId    = 12;
$entry->authorId  = 123;
$entry->enabled   = true;
$entry->getContent()->title = "Here goes my title!";

// new matrix and matrix block
$block = array();
$block['new1'] = array(
    'type' => 'body',
    'enabled' => true,
    'fields' => array(
        'text' => 'Here goes my article.'
    )
);

// add content to entry including created matrix
$entry->setContentFromPost(array(
    'description' => "And of course the description...",
    'matriz' => $block,
));

// save entry
$success = craft()->entries->saveEntry($entry);

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.