You are here

function arrange_fields_get_form_fields in Arrange Fields 7

Same name and namespace in other branches
  1. 6 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 1137

Code

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

      /*      // Is this element a fieldset and part of the additional_settings
            // vertical tabs group?  If so, let's exclude it.
            if (isset($element["#group"])
                && $element["#group"] == "additional_settings") {

                continue;
            }
      */

      // Regarding the code above, I *think* it would be safe to exclude
      // ANY element which has it's #group property set, because this is
      // only used when adding a fieldset to a vertical tab, and in Arrange Fields
      // we are just going to ignore those.
      if (isset($element["#group"]) && $element["#group"] != "") {
        continue;
      }

      // Is this the buttons element on a node 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" && !isset($element["#type"]) && isset($element["submit"]) && $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 Fields 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;
}