You are here

function arrange_fields_get_form_fields in Arrange Fields 6

Same name and namespace in other branches
  1. 7 arrange_fields.module \arrange_fields_get_form_fields()

This function uses recursion to go through an array (presumably $form). It will return back an array of references to fields which we might want to place wrappers around.

It is meant to be used by arrange_fields_add_draggable_wrappers().

Parameters

array $arr:

string $previous_key:

Return value

array

1 call to arrange_fields_get_form_fields()
arrange_fields_add_draggable_wrappers in ./arrange_fields.module
In this function, we are going to add div's around elements we wish to make draggable on the page. The jQuery can then grab onto those divs to make them draggable.

File

./arrange_fields.module, line 342

Code

function arrange_fields_get_form_fields(&$arr, $previous_key = "") {
  $rtn = array();
  foreach ($arr as $name => &$element) {
    if (is_array($element)) {

      // Is this the buttons element on a CCK form?  If so, we want
      // the entire buttons array, NOT each individual button (this was
      // causing a bug where Diff's View changes and the Delete button
      // were not arrangeable.
      if ($name == "buttons" && $element["#type"] == "" && $element["submit"]["#type"] == "submit") {

        // Okay, we found it (most likely, anyway).
        // Let's add it to our return array.
        $rtn[] = array(
          "name" => $name,
          "element" => &$element,
        );
      }
      elseif (isset($element["#type"]) && $element["#type"] != "hidden" && $element["#type"] != "token" && $element["#type"] != "value") {

        // We found an element!  Save its reference in our return array.
        // If the name is numeric (as is the case with some CCK elements), we
        // actually want to use the previous element.
        if (is_numeric($name) && $previous_key != "") {

          // Let's use the previous element here, which should be $arr.
          $rtn[] = array(
            "name" => $previous_key,
            "element" => &$arr,
          );
        }
        else {

          // Add to our return array.
          $rtn[] = array(
            "name" => $name,
            "element" => &$element,
          );
        }
      }
      else {

        // This is not a field, but possibly another level of nesting
        // in our $form.  So, let's recursively call this function
        // and explore this new level.
        $temp = arrange_fields_get_form_fields($element, $name);

        // It's possible we did indeed find some fields in the nested sub-array
        // we just explored.  If so, let's add it to the end of our on-going
        // return array.
        $rtn = array_merge($rtn, $temp);
      }
    }
  }
  return $rtn;
}