Creating a matrix entry with a plugin I'm working on a plugin to save user profile data. I have a matrix field called addressMatrix, I've made address a matrix because users can save multiple addresses. Every address entry will have the following fields:


streetAddress
city
stateProvince
postalCode
country


NOTE: I did associate the field with users.

All I want to do is to be able to save a new address or update an existing address for each user. I have no idea where to begin.

I've looked at 1 or 2 Stack Exchange posts on the matter but it does not look like anyone else has raised this question. Sorry in advance... I have no code to post as I don't even have a solid starting point.

Thank you for any help you can provide.

UPDATE

Here's the code I have thus far:

// Load the user
$userModel = craft()-&gt;users-&gt;getUserById($profileDataModel-&gt;userId);

// Load the matrix field
$addressMatrix = craft()-&gt;fields-&gt;getFieldByHandle("addressMatrix");

$block = new MatrixBlockModel();
$block-&gt;fieldId    = $addressMatrix-&gt;id; // Matrix field's ID
$block-&gt;ownerId    = $userModel-&gt;id; // ID of entry the block should be added to
$block-&gt;typeId     = 7; // ID of block type

$block-&gt;getContent()-&gt;setAttributes(array(
    'streetAddress' =&gt; '1523 Kansas Ave'
));

$success = craft()-&gt;matrix-&gt;saveBlock($block);


The above does work, but what I'm current stumped on is how to get the type ID programmatically. I should be able to get a block ID by the block handle. Looking through the class reference I don't see it.
In case anyone is interested this is how I solved the problem:

First load the matrix field:

$addressMatrix = craft()-&gt;fields-&gt;getFieldByHandle("addressMatrix");


Then get all of the blocks of the matrix field:

$addressMatrixBlocks = craft()-&gt;matrix-&gt;getBlockTypesByFieldId($addressMatrix-&gt;id);


Next iterate over the blocks looking for a specific handle:

foreach($addressMatrixBlocks as $key =&gt; $data){ 

    if($data-&gt;handle === "address"){ 

    $addressBlock = $data; 
    break; 

    }; 

};


Now you have your block. To get the ID just do this:

echo $addressBlock-&gt;id;