You are here

function slickgrid_callback_get_form_element in Slickgrid 6

1 call to slickgrid_callback_get_form_element()
slickgrid_node_form_pre_render in ./slickgrid.module

File

./slickgrid.module, line 861

Code

function slickgrid_callback_get_form_element(&$form, $field_name) {
  static $element_exists;
  foreach (element_children($form) as $key) {

    // If this isn't the field we're looking for it needs to be removed from the form
    if ($key === $field_name || $form[$key]['#name'] == $field_name) {

      // tidy up the form a bit by removing fieldsets if the field is in one
      if ($form['#type'] == 'fieldset') {
        unset($form['#type']);
      }
      $element_exists = true;
    }
    else {
      if (count(element_children($form[$key]))) {

        // If this item has children, call again
        slickgrid_callback_get_form_element($form[$key], $field_name);
      }
      if (!count(element_children($form[$key]))) {

        // If there are no children & it's not a requried field, unset it
        // Keep all hidden elements
        // these will containf form build id etc.,
        if (!in_array($key, array(
          'form_build_id',
          'form_id',
        )) || is_numeric($key)) {
          unset($form[$key]);
        }
      }
    }
  }
  return $element_exists;
}