Get the handle of a Matrix block I am performing the following query, which returns me an array of matrix blocks:

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::MatrixBlock);
$criteria-&gt;relatedTo = array(someCoolId, anotherCoolId);
$relatedStories = $criteria-&gt;find();


When looping through this array, I was wondering if it was possible to access the handle of the matrix block that I am currently in. Reason being is I would like to retrieve this as a string, and perform some type of work on it.
You can grab the handle of an element that has different types (entries, matrix) with getType()-&gt;handle for example:

$handle = $entry-&gt;getType()-&gt;handle


In your case

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::MatrixBlock);
$criteria-&gt;relatedTo = array(someCoolId, anotherCoolId);
$relatedStories = $criteria-&gt;find();
foreach ($relatedStories as $block){
    $handle = $block-&gt;getType()-&gt;handle;
    switch ($handle){
        case 'foo':
            break;
    }
}


Edit:

Not sure what you mean exactly so I'll just insert some random code parts until something is correct.

// get the parent element -&gt; the owner of that block.
$parent = $block-&gt;getOwner()

// get the field that relates both elements
$field = craft()-&gt;fields-&gt;getFieldById($block-&gt;fieldId);
$fieldHandle = $field-&gt;handle;