Plugin to add new item type and elements

I wonder if anyone has any idea why this isn't working?

The item type is successfully created but the elements are not created/assigned.

<?php

class MyItemTypePlugin extends Omeka_Plugin_AbstractPlugin
{
    // Item Type
    const ITEM_TYPE_NAME = 'My Item Type Name';
    const ITEM_TYPE_DESCRIPTION = '...';

    // Elements
    const ELEMENT_SUBTITLE = 'Subtitle';
    const ELEMENT_SUBTITLE_DESCRIPTION = '...';
    const ELEMENT_LEDE = 'Lede';
    const ELEMENT_LEDE_DESCRIPTION  = '...';
    const ELEMENT_STORY = 'Story';
    const ELEMENT_STORY_DESCRIPTION  = '...';
    const ELEMENT_SPONSOR = 'Sponsor';
    const ELEMENT_SPONSOR_DESCRIPTION  = '...';
    const ELEMENT_FACTOID = 'Factoid';
    const ELEMENT_FACTOID_DESCRIPTION  = '...';
    const ELEMENT_RELATED = 'Related Resources';
    const ELEMENT_RELATED_DESCRIPTION  = '...';

    protected $_hooks = array('install');

    public function hookInstall(){  

	    $elements = array(
			array(
				'name'=>self::ELEMENT_SUBTITLE,
				'description'=>self::ELEMENT_SUBTITLE_DESCRIPTION,
				'order'=>1
				),
			array(
				'name'=>self::ELEMENT_LEDE,
				'description'=>self::ELEMENT_LEDE_DESCRIPTION,
				'order'=>2
				),
			array(
				'name'=>self::ELEMENT_STORY,
				'description'=>self::ELEMENT_STORY_DESCRIPTION,
				'order'=>3
				),
			array(
				'name'=>self::ELEMENT_SPONSOR,
				'description'=>self::ELEMENT_SPONSOR_DESCRIPTION,
				'order'=>4
				),
			array(
				'name'=>self::ELEMENT_FACTOID,
				'description'=>self::ELEMENT_FACTOID_DESCRIPTION,
				'order'=>5
				),
			array(
				'name'=>self::ELEMENT_RELATED,
				'description'=>self::ELEMENT_RELATED_DESCRIPTION,
				'order'=>6
				)
		); 		

		// Sort out which elements already exist
		$add_elements=array();

		foreach($elements as $element){

			if(!element_exists('Item Type Metadata',$element['name'])){

				// add the new elements

				$add_elements[$element];

			}else{

				// add the existing Element objects

				$ElementObj=get_records('Element',array(
					'elementSet'=>'Item Type Metadata',
					'name'=>$element['name']),1);

				$add_elements[$ElementObj];

			}
		}

		insert_item_type(
			array(
			  'name'=> self::ITEM_TYPE_NAME,
			  'description' => self::ITEM_TYPE_DESCRIPTION,
			),
			$add_elements
		);
	}
}

Not entirely sure if this is it--I haven't tried the code yet--but get_record() (which I now notice is not in our documentation. oops) instead of get_records() might serve you better. get_records() always returns an array, even if the limit is 1. get_record() returns just the object (if found).

Plus, I'm guessing you mean:

$add_elements[] = $element;
$add_elements[] = $ElementObj;

instead of what you have for adding to the array.

Oh wow, how did I not see that? Thanks Patrick!