commit 63fdc4ce21a69d05cc27bb2effc5025b275814c9
Author: Raphael Spencer <raphael@skyleafdesign.com>
Date:   Wed Jan 1 15:29:45 2014 -0600

    Issue #2162393 by micromegas: Added support for entity_create()

diff --git a/flag.module b/flag.module
index 39d7f3d..9ccb862 100644
--- a/flag.module
+++ b/flag.module
@@ -33,6 +33,7 @@ function flag_entity_info() {
       // The following tells EntityAPI how to save flaggings, thus allowing use
       // of Entity metadata wrappers (if present).
       'save callback' => 'flagging_save',
+      'creation callback' => 'flagging_create',
     ),
   );
 
@@ -73,6 +74,35 @@ function flagging_load($flagging_id, $reset = FALSE) {
 }
 
 /**
+ * Creates a skeleton flagging entity object for use with $flag::flag().
+ *
+ * @param $values
+ *   An array of values as described by the entity's property info. Only 
+ *   'flag_name' or 'fid' must be specified, since $flag::flag() does the rest.
+ *
+ * @return
+ *   An object array containing the property values
+ */
+function flagging_create($values = array()) {
+  $flagging = (object) array();
+  
+  if (!array_key_exists('flag_name', $values)) {
+    if (array_key_exists('fid', $values)) {
+      // add flag_name, determined from fid
+      $flag = flag_get_flag(NULL, $values['fid']);
+      $values['flag_name'] = $flag->name;
+    }
+  }
+
+  // Apply the given values.
+  foreach ($values as $key => $value) {
+    $flagging->$key = $value;
+  }
+
+  return $flagging;
+}
+
+/**
  * Saves a flagging entity.
  *
  * For a new flagging, throws an exception is the flag action is not allowed for
