From a1ade859dd5bba3df027765976843658ad6787b2 Mon Sep 17 00:00:00 2001
From: Claudiu Cristea <clau.cristea@gmail.com>
Date: Fri, 9 Sep 2011 20:13:12 +0300
Subject: [PATCH] #107: In the FB image show the avatars and a small branding
 icon/logo

---
 includes/form.inc |   28 +++++-----------------------
 1 files changed, 5 insertions(+), 23 deletions(-)

diff --git a/includes/form.inc b/includes/form.inc
index df1b2f7..0f668b3 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -2098,32 +2098,14 @@ function form_state_values_clean(&$form_state) {
   // form_builder() collects all button elements in a form. We remove the button
   // value separately for each button element.
   foreach ($form_state['buttons'] as $button) {
-    // Remove this button's value from the submitted form values by finding
-    // the value corresponding to this button.
-    // We iterate over the #parents of this button and move a reference to
-    // each parent in $form_state['values']. For example, if #parents is:
-    //   array('foo', 'bar', 'baz')
-    // then the corresponding $form_state['values'] part will look like this:
-    // array(
-    //   'foo' => array(
-    //     'bar' => array(
-    //       'baz' => 'button_value',
-    //     ),
-    //   ),
-    // )
-    // We start by (re)moving 'baz' to $last_parent, so we are able unset it
-    // at the end of the iteration. Initially, $values will contain a
-    // reference to $form_state['values'], but in the iteration we move the
-    // reference to $form_state['values']['foo'], and finally to
-    // $form_state['values']['foo']['bar'], which is the level where we can
-    // unset 'baz' (that is stored in $last_parent).
-    $parents = $button['#parents'];
     $values = &$form_state['values'];
+    $parents = $button['#parents'];
     $last_parent = array_pop($parents);
-    foreach ($parents as $parent) {
-      $values = &$values[$parent];
+    $key_exists = NULL;
+    drupal_array_get_nested_value($values, $parents, $key_exists);
+    if ($key_exists) {
+      unset($values[$last_parent]);
     }
-    unset($values[$last_parent]);
   }
 }
 
-- 
1.7.5.4

