You are here

function finder_form_skip_empty in Finder 7.2

Skip empty.

Recursively handle skip empty setting.

1 call to finder_form_skip_empty()
finder_form in includes/form.inc
FAPI definition for the finder form.

File

includes/form.inc, line 277
The finder form.

Code

function finder_form_skip_empty($form, $finder) {
  $children = element_children($form);
  foreach ($children as $child) {
    if (isset($finder->elements[$child])) {
      $form[$child] = finder_form_skip_empty($form[$child], $finder);
      if ($finder->elements[$child]->element_handler['type'] == 'container') {

        // Containers are considered empty if they contain no child elements.
        if ($finder
          ->esetting($finder->elements[$child], 'skip_empty')) {
          $child_children = element_children($form[$child]);
          if (empty($child_children)) {
            unset($form[$child]);
          }
        }
      }
      else {
        if ($finder
          ->esetting($finder->elements[$child], 'skip_empty')) {

          // Forms are considered empty if there are zero or one choices.
          $finder->find = array(
            'mode' => 'choices',
            'keywords' => array(
              $finder->elements[$child]->id => array(
                NULL,
              ),
            ),
            'element' => $finder->elements[$child],
          );
          $finder
            ->find();
          if (count($finder->find['results']) <= 1) {
            unset($form[$child]);
          }
        }
      }
    }
  }
  return $form;
}