# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- /insert/insert.module
+++ /insert/insert.module
@@ -41,7 +41,7 @@
 
     // Theme functions in includes/insert.inc.
     'insert_image' => array(
-      'variables' => array('item' => NULL, 'widget' => NULL),
+      'variables' => array('item' => NULL, 'widget' => NULL, 'entity' => NULL),
       'template' => 'templates/insert-image',
       'file' => 'includes/insert.inc',
     ),
@@ -145,14 +145,14 @@
 /**
  * Given an item and an insert style, return the output.
  */
-function insert_content($item, $style, $widget) {
-  return module_invoke($style['module'], 'insert_content', $item, $style, $widget);
+function insert_content($item, $style, $widget, $entity) {
+  return module_invoke($style['module'], 'insert_content', $item, $style, $widget, $entity);
 }
 
 /**
  * Process function for insert-enabled fields.
  */
-function insert_element_process($element) {
+function insert_element_process($element, &$form_state) {
   static $js_added;
 
   // Bail out early if the needed properties aren't available. This happens
@@ -163,6 +163,7 @@
 
   $item = $element['#value'];
   $field = field_info_field($element['#field_name']);
+  $item['field_name'] = $element['#field_name'];
   $instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
 
   $widget_settings = $instance['widget']['settings'];
@@ -173,6 +174,30 @@
     return $element;
   }
 
+  switch ($element['#entity_type']) {
+    case 'node':
+      // We use an light node object to reduce the memory usage.
+      $entity = new stdClass();
+      $entity->entity_type = 'node';
+      $entity->nid = $form_state['node']->nid;
+      $entity->type = $form_state['node']->type;
+      $entity->uid = $form_state['node']->uid;
+      $entity->title = $form_state['node']->title;
+      break;
+    case 'comment':
+      $entity = new stdClass();
+      $entity->entity_type = 'comment';
+      $entity->cid = $form_state['comment']->cid;
+      $entity->subject = $form_state['comment']->subject;
+      break;
+    case 'taxonomy_term':
+      $entity = new stdClass();
+      $entity->entity_type = 'taxonomy_term';
+      $entity->tid = $form_state['term']->tid;
+      $entity->name = $form_state['term']->name;
+      break;
+  }
+  
   // Add base settings only once.
   if (!isset($js_added)) {
     $js_added = array();
@@ -208,7 +233,7 @@
       if ($enabled && ($style = insert_style_load($style_name))) {
         $element['insert_templates'][$style_name] = array(
           '#type' => 'hidden',
-          '#value' => insert_content($item, $style, $instance['widget']),
+          '#value' => insert_content($item, $style, $instance['widget'], $entity),
           '#id' => $element['#id'] . '-insert-template-' . str_replace('_', '-', $style_name),
           '#name' => $element['#name'] . '[insert_template][' . $style_name . ']',
           '#attributes' => array('class' => array('insert-template')),
